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;
typedef long long ll;
typedef vector<int>vi;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define FOR(i,a,b) for(int i=a; i<b; i++)
//-----------------------------------------------------
const int MX=2e5+10;
int memo[MX][2];
int cnt=0;
vi query(int i){
if(memo[i][0]==-1){
vi vec=ask(i);
cnt++;
if(cnt>10000) assert(0);
memo[i][0]=vec[0];
memo[i][1]=vec[1];
}
return vi{memo[i][0],memo[i][1]};
}
int find_best(int N){
memset(memo,-1,sizeof(memo));
int lft=0;
while(lft<N){
int l=lft,r=N-1,rgt;
vi v=query(lft);
if(v[0]+v[1]==0) return lft;
while(l<=r){
int m=(l+r)/2;
vi vv=query(m);
if(v[0]+v[1]!=vv[0]+vv[1])
r=m-1;
else{
if(v[0]==vv[0]){
rgt=m;
l=m+1;
}
else r=m-1;
}
}
lft=rgt+1;
}
assert(0);
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:55:6: warning: 'rgt' may be used uninitialized in this function [-Wmaybe-uninitialized]
55 | lft=rgt+1;
| ~~~^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |