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 <bits/stdc++.h>
#include "prize.h"
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n")
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define vv vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int inf = 2e09; ll infll = 2e18; int mod = 119<<23|1;
//~ #ifdef LOCAL
//~ vector<int> ask(int i){ return vector<int>(2, 0); }
//~ #endif
int SUM; // bound na checka, czy to jest gosc z lepszej, czy nie
mt19937 rng(34);
int f(int l, int r, int resl, int resr){
//~ printf("%d %d\n", l, r);
int midl = (l+r)/2, midr = (l+r)/2;
int result = 0;
vv<int> tmp = ask(midl), tmp2 = tmp; int sum = tmp[0]+tmp[1];
while(sum != SUM && l < midl-1){
if(!sum){ return midl;}
--midl;
tmp = ask(midl); sum = tmp[0]+tmp[1];
}
if(!sum) return midl;
if(sum == SUM && resl != tmp[0]) result = max(result, f(l, midl, resl, tmp[0]));
sum = tmp2[0]+tmp2[1];
while(sum != SUM && midr+1 < r){
if(!sum) return midr;
++midr;
tmp = ask(midr); sum = tmp[0]+tmp[1];
}
if(!sum) return midr;
if(sum == SUM && resr != tmp[0]) result = max(result, f(midr, r, tmp[0], resr));
return result;
}
int find_best(int n){
//~ if(n <= 5000){
//~ vv<int> tmp; int result = 0;
//~ for(int i = 0; i < n; ++i){
//~ tmp = ask(i);
//~ if(!(tmp[0]+tmp[1])){ result = i; break; }
//~ } return result;
//~ }
for(int i = 0; i < 50; ++i){
int x = rng()%n;
vv<int> tmp = ask(x); int sum = tmp[0]+tmp[1];
SUM = max(SUM, sum);
if(!sum) return x;
}
int l = 0, r = n-1, resl = 0, resr = 0;
vv<int> tmp;
for(int i = 0; i < n; ++i){
tmp = ask(i); int sum = tmp[0]+tmp[1];
if(sum == SUM){ l = i, resl = tmp[0]; break; }
else if(!sum) return i;
}
for(int i = n-1; ~i; --i){
tmp = ask(i); int sum = tmp[0]+tmp[1];
if(sum == SUM){ r = i, resr = tmp[0]; break; }
else if(!sum) return i;
}
return f(l, r, resl, resr);
}
//~ #ifdef LOCAL
//~ int main(){
//~ int T = 1;
//~ for(++T; --T; ) find_best(T);
//~ return 0;
//~ }
//~ #endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |