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 ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
vector<int> v;
map<int,pair<int,int> > mp;
bool check[200005];
int ans,mx,N;
int solve(int k){
for(int i=0; i<k; i++){
vector<int> vv;
vv=ask(i);
if(vv[0]==0 && vv[1]==0){
return i;
}
}
return 0;
}
void dfs(int x, int y){
if(x>y) return;
int a,b,c,d;
if(check[x]==1){
a=mp[x].ff;
b=mp[x].ss;
}
else{
vector<int> v1=ask(x);
a=v1[0];
b=v1[1];
check[x]=1;
mp[x].ff=a;
mp[x].ss=b;
}
if(x==y){
if(a+b!=mx) v.pb(x);
return;
}
if(check[y]==1){
c=mp[y].ff;
d=mp[y].ss;
}
else{
vector<int> v2=ask(y);
c=v2[0];
d=v2[1];
mp[y].ff=c;
mp[y].ss=d;
check[y]=1;
}
if(a+b==mx && c+d==mx){
if(c-a==0 || y-x==1) return;
int mid=(x+y)/2;
dfs(x,mid);
dfs(mid+1,y);
}
else{
if(a+b<mx && c+d<mx){
v.pb(x);
v.pb(y);
if(y-x>=2){
int mid=((y-1)+(x+1)/2);
if(mid<N) dfs(x+1,mid);
dfs(mid+1,y-1);
}
return;
}
if(a+b<mx){
v.pb(x);
if(x+1<y){
int mid=(x+1+y)/2;
dfs(x+1,mid);
dfs(mid+1,y);
}
return;
}
v.pb(y);
if(x<y-1){
int mid=(x-1+y)/2;
dfs(x,mid);
dfs(mid+1,y-1);
}
}
}
int find_best(int n) {
N=n;
if(n<=4000){
return solve(n);
}
for(int i=0; i<min(500,n); i++){
vector<int> vv;
vv=ask(i);
check[i]=1;
mp[i].ff=vv[0];
mp[i].ss=vv[1];
mx=max(mx,vv[0]+vv[1]);
}
int l=0;
int r=n-1;
dfs(l,r);
for(int i=0; i<v.size(); i++){
vector<int> vv;
vv=ask(v[i]);
if(vv[0]==0 && vv[1]==0){
return v[i];
}
}
return ans;
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:110:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | for(int i=0; i<v.size(); i++){
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |