Идея: BledDest, подготовка: BledDest
Разбор
Tutorial is loading...
Решение (BledDest)
t = int(input())
for i in range(t):
x, y = map(int, input().split())
xc = -1
yc = -1
for j in range(0, 51):
for k in range(0, 51):
if 2 * (j + k) == x + y and 2 * (abs(x - j) + abs(y - k)) == x + y:
xc, yc = j, k
print(xc, yc)
Идея: MikeMirzayanov, подготовка: MikeMirzayanov
Разбор
Tutorial is loading...
Решение (BledDest)
t = int(input())
for i in range(t):
n, a, b = map(int, input().split())
p = [a]
for j in range(n, 0, -1):
if j != a and j != b:
p.append(j)
p.append(b)
if(len(p) == n and min(p[0:n//2]) == a and max(p[n//2:n]) == b):
print(*p)
else:
print(-1)
Идея: vovuh, подготовка: vovuh
Разбор
Tutorial is loading...
Решение (vovuh)
#include <bits/stdc++.h>
using namespace std;
long long get(int x) {
return x * 1ll * (x + 1) / 2;
}
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
int k;
long long x;
cin >> k >> x;
long long l = 1, r = 2 * k - 1;
long long res = 2 * k - 1;
bool over = false;
while (l <= r) {
int mid = (l + r) >> 1;
if (mid >= k) {
over = (get(k) + get(k - 1) - get(2 * k - 1 - mid) >= x);
} else {
over = (get(mid) >= x);
}
if (over) {
res = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
cout << res << endl;
}
return 0;
}
Идея: vovuh, подготовка: vovuh
Разбор
Tutorial is loading...
Решение (vovuh)
#include <bits/stdc++.h>
using namespace std;
bool get(long long a, long long b, long long x) {
if (a == x || b == x) return true;
if (a < b) swap(a, b);
if (b > a - b) b = a - b;
if (x > max(a, b) || a == 0 || b == 0) return false;
long long cnt = max(1ll, (a - max(x, b)) / (2 * b));
return get(a - b * cnt, b, x);
}
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
long long a, b, x;
cin >> a >> b >> x;
if (get(a, b, x)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
Идея: BledDest, подготовка: BledDest
Разбор
Tutorial is loading...
Решение (BledDest)
#include <bits/stdc++.h>
using namespace std;
const int N = 200043;
const int K = 20;
vector<int> idx[N];
int m[N], k[N];
bool frac_greater(pair<int, int> a, pair<int, int> b)
{
return a.first * b.second > a.second * b.first;
}
int main()
{
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%d %d", &m[i], &k[i]);
idx[m[i]].push_back(i);
}
vector<int> cert;
pair<int, int> ans = {0, 1};
for(int i = 1; i <= K; i++)
{
vector<int> score(N);
for(int j = 0; j < n; j++)
score[m[j]] += min(i, k[j]);
vector<pair<int, int>> aux;
for(int j = 0; j < N; j++)
aux.push_back(make_pair(score[j], j));
sort(aux.rbegin(), aux.rend());
pair<int, int> cur_ans = {0, i};
vector<int> cur_cert;
for(int j = 0; j < i; j++)
{
cur_ans.first += aux[j].first;
cur_cert.push_back(aux[j].second);
}
if(frac_greater(cur_ans, ans))
{
ans = cur_ans;
cert = cur_cert;
}
}
cout << cert.size() << endl;
shuffle(cert.begin(), cert.end(), mt19937(time(NULL)));
for(auto x : cert) cout << x << " ";
cout << endl;
}
Идея: BledDest, подготовка: BledDest
Разбор
Tutorial is loading...
Решение (BledDest)
#include<bits/stdc++.h>
using namespace std;
int n, m;
#define x first
#define y second
typedef pair<int, int> comb;
comb norm(const comb& a)
{
return make_pair(min(a.x, n), min(a.y, m));
}
bool good(const comb& a)
{
return a.x == n || a.y == m;
}
bool comp(const comb& a, const comb& b)
{
if(a.x != b.x)
return a.x > b.x;
return a.y > b.y;
}
int main()
{
scanf("%d %d", &n, &m);
int v;
scanf("%d", &v);
set<comb> s;
for(int i = 0; i < v; i++)
{
int x, y;
scanf("%d %d", &x, &y);
s.insert(make_pair(x, y));
}
int steps = 0;
vector<comb> cur;
cur.push_back(make_pair(1, 1));
while(true)
{
if(cur[0] == make_pair(n, m))
break;
vector<comb> ncur;
for(auto x : cur)
{
int sum = x.x + x.y;
if(s.count(x))
sum++;
comb z = x;
z.x = sum;
ncur.push_back(norm(z));
z = x;
z.y = sum;
ncur.push_back(norm(z));
}
sort(ncur.begin(), ncur.end(), comp);
int mx = 0;
vector<comb> ncur2;
for(auto x : ncur)
{
if(x.y <= mx) continue;
mx = max(mx, x.y);
ncur2.push_back(x);
}
cur = ncur2;
steps++;
}
printf("%d\n", steps);
}
1612G - Массив максимальной суммы
Идея: adedalic, подготовка: adedalic
Разбор
Tutorial is loading...
Решение (adedalic)
#include<bits/stdc++.h>
using namespace std;
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define sz(a) int((a).size())
#define x first
#define y second
typedef long long li;
typedef pair<int, int> pt;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
return out << "(" << p.x << " " << p.y << ")";
}
template<class A> ostream& operator <<(ostream& out, const vector<A> &v) {
fore(i, 0, sz(v)) {
if(i) out << " ";
out << v[i];
}
return out;
}
const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = int(1e9) + 7;
int norm(int a) {
while (a >= MOD)
a -= MOD;
while (a < 0)
a += MOD;
return a;
}
int mul(int a, int b) {
return int(a * 1ll * b % MOD);
}
const int MX = int(1e6) + 55;
int n;
li total;
int cnt[MX];
inline bool read() {
if(!(cin >> n))
return false;
total = 0;
fore (i, 0, n) {
int k; cin >> k;
cnt[k]++;
total += k;
}
return true;
}
int fact[MX];
inline void solve() {
fact[0] = 1;
fore (i, 1, MX)
fact[i] = mul(fact[i - 1], i);
int ansSum = 0;
int ansCnt = 1;
for (int lvl = MX - 1; lvl > 1; lvl--) {
ansCnt = mul(ansCnt, mul(fact[cnt[lvl]], fact[cnt[lvl]]));
//each color gives (lvl - 1) * (r_i - l_i)
// or (lvl - 1) * (sum r_i - sum l_i)
// l_i is permutation of [0,..., cnt[lvl]), so sum l_i = (cnt[lvl] - 1) * cnt[lvl] / 2
// r_i is permutation of [total - cnt[lvl],..., total), so sum = cnt[lvl] * (total - cnt[lvl]) + (cnt[lvl] - 1) * cnt[lvl] / 2
ansSum = norm(ansSum + mul(mul(lvl - 1, cnt[lvl]), (total - cnt[lvl]) % MOD));
total -= 2 * cnt[lvl];
cnt[lvl - 2] += cnt[lvl];
}
ansCnt = mul(ansCnt, fact[cnt[1]]);
cout << ansSum << " " << ansCnt << endl;
}
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
int tt = clock();
#endif
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
if(read()) {
solve();
#ifdef _DEBUG
cerr << "TIME = " << clock() - tt << endl;
tt = clock();
#endif
}
return 0;
}














