This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Sylwia Sapkowska
#include <bits/stdc++.h>
#include "prize.h"
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << "'" << x << "'";}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef pair<int, int> T;
// mt19937 rng(chrono::steady_clock().time_since_epoch().count());
// int p(int a, int b){
// return a + rng()%(b-a+1);
// }
int find_best(int n) {
int curr = 0;
vector<int>tab(n+1);
for (int rep = 1; rep <= min(n, 500); rep++){
auto x = ask(rep-1);
if (max(x[0], x[1]) == 0) return rep-1;
int s = x[0] + x[1];
tab[rep] = s;
curr = max(curr, s);
}
vector<int>where, pref(n+1);
vector<bool>vis(n+1);
for (int rep = 1; rep <= min(n, 500); rep++){
if (tab[rep] < curr){
vis[rep] = 1;
}
}
// debug(pos);
// int left = n-curr; //tyle nie najgorszych elementow
//powinno byc left <= 500
vector<array<int, 2>>pre(n+1, {-1, -1});
while (1){
where.clear();
pref.assign(n+1, 0);
for (int rep = 0; rep <= n; rep++){
if (!vis[rep]){
where.emplace_back(rep);
}
if (vis[rep]) pref[rep]++;
if (rep) pref[rep] += pref[rep-1];
}
int l = 1, r = (int)where.size()-1;
int ans = -1;
while (r >= l){
int m = (l+r)/2;
int pos = where[m];
if (pre[pos][0] == -1){
auto y = ask(pos-1);
pre[pos][0] = y[0];
pre[pos][1] = y[1];
}
auto x = pre[where[m]];
if (x[0] + x[1] == 0) return pos-1;
if (x[0] + x[1] < curr){
ans = pos;
break;
}
//najgorszy
if (x[0] == pref[pos]){
l = m+1;
} else {
r = m-1;
}
}
// debug(ans);
if (ans == -1) break;
vis[ans] = 1;
// debug(ans);
}
assert(false);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |