This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
using ii = pair<int, int>;
int n;
vector<int> V[200007];
ii ans(int i) {
if(V[i].size() == 0)
V[i] = ask(i);
return {V[i][0], V[i][1]};
}
int worst_sum;
int find_in_segment(int a, int b, int ok) {
if(!ok)
return -1;
int mid1 = (a + b) / 2;
while(ans(mid1).X + ans(mid1).Y != worst_sum && mid1 >= a) {
if(ans(mid1).X + ans(mid1).Y == 0)
return mid1;
mid1--;
}
if(mid1 > a) {
int x = find_in_segment(a, mid1 - 1, ans(mid1).X - ans(a - 1).X);
if(x != -1)
return x;
}
if(mid1 < b) {
int x = find_in_segment(mid1 + 1, b, ans(b + 1).X - ans(mid1).X);
if(x != -1)
return x;
}
return -1;
}
int find_best(int n) {
::n = n;
int pocz = 0, kon = n - 1;
while(pocz <= min(474, n)) {
worst_sum = max(worst_sum, ans(pocz).X + ans(pocz).Y);
if(ans(pocz).X + ans(pocz).Y == 0)
return pocz;
pocz++;
}
while(ans(pocz).X + ans(pocz).Y != worst_sum) {
if(ans(pocz).X + ans(pocz).Y == 0)
return pocz;
pocz++;
}
while(ans(kon).X + ans(kon).Y != worst_sum) {
if(ans(kon).X + ans(kon).Y == 0)
return kon;
kon--;
}
pocz++;
kon--;
return find_in_segment(pocz, kon, ans(kon + 1).X - ans(pocz - 1).X);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |