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;
const int jump = 128;
int find_best(int n) {
mt19937 rng(0);
int mx_sum = 0;
for(int k = 0; k < 500; k++) {
auto v = ask(rng() % n);
mx_sum = max(mx_sum, v[0]+v[1]);
}
for(int i = 0; i < n; i++) {
auto v = ask(i);
int sum = v[0]+v[1];
if(sum == 0) {
return i;
}
if(sum == mx_sum) {
vector<int> v_p;
if(i+jump < n) {
v_p = ask(i+jump);
if(v_p[0]+v_p[1] == mx_sum && v[0] == v_p[0]) {
i += jump;
continue;
}
}
int l = i, r = min(i+jump, n-1);
while(l < r) {
int m = (l+r+1)/2;
v_p = ask(m);
int sum_p = v_p[0]+v_p[1];
if(sum_p < mx_sum || v_p[0] > v[0]) {
r = m-1;
}
else {
l = m;
}
}
i = l;
}
}
return 0;
}
/*
5
2 2 2 1 2
8
3 3 2 3 3 2 1 3
sample:
8
3 2 3 1 3 3 2 3
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |