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];
int worst_sum;
ii ans(int i) {
if(V[i].size() == 0) {
V[i] = ask(i);
worst_sum = max(worst_sum, V[i][0] + V[i][1]);
}
return {V[i][0], V[i][1]};
}
int sum(int i) {
return ans(i).X + ans(i).Y;
}
int find_in_segment(int a, int b, int ok) {
if(!ok)
return -1;
int mid1 = (a + b) / 2;
int mid2 = (a + b) / 2;
for(int i = 0 ; i < 5 ; i++) {
while(sum(a - 1) < worst_sum && a <= mid1) {
if(sum(a) == 0)
return a;
a++;
}
while(sum(b + 1) < worst_sum && mid1 <= b) {
if(sum(b) == 0)
return b;
b--;
}
while(sum(mid1) < worst_sum && mid1 >= a) {
if(sum(mid1) == 0)
return mid1;
mid1--;
}
while(sum(mid2) < worst_sum && mid2 <= b) {
if(sum(mid2) == 0)
return mid2;
mid2++;
}
}
if(mid1 > a) {
int x = find_in_segment(a, mid1 - 1, ans(mid1).X - ans(a - 1).X);
if(x != -1)
return x;
}
if(mid2 < b) {
int x = find_in_segment(mid2 + 1, b, ans(b + 1).X - ans(mid2).X);
if(x != -1)
return x;
}
return -1;
}
int find_best(int n) {
::n = n;
int total = ans(0).Y;
worst_sum = total;
V[n] = {total, 0};
if(total == 0)
return 0;
return find_in_segment(1, n - 1, total);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |