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>
#define F first
#define S second
using namespace std;
pair<int,int>p,p1;
vector<int>v,v1;
int A[200005];
int ANS[200005];
int ANS1[200005];
int ans=-1;
void go(int L,int R)
{
if(ans>=0)return ;
if(L>R)return;
if(L==R)
{
v.clear();
if(ANS[L]>=0)
v.push_back(ANS[L]),v.push_back(ANS1[L]);
else
v=ask(L),ANS[L]=v[0],ANS1[L]=v[1];
A[v[0]]=min(A[v[0]],L);
if(v[0]+v[1]==0)
{
ans=L;
return;
}
return;
}
else
{
v1.clear();
if(ANS[R]>=0)
v1.push_back(ANS[R]),v1.push_back(ANS1[R]);
else
v1=ask(R),ANS[R]=v1[0],ANS1[R]=v1[1];
A[v1[0]]=min(A[v1[0]],R);
if(v1[0]+v1[1]==0)
{
ans=R;
return;
}
v.clear();
if(ANS[L]>=0)
v.push_back(ANS[L]),v.push_back(ANS1[L]);
else
v=ask(L),ANS[L]=v[0],ANS1[L]=v[1];
A[v[0]]=min(A[v[0]],L);
if(v[0]+v[1]==0)
{
ans=L;
return;
}
if(v[0]==v1[0] || v[1]==v1[1])return;
int mid=(L+R)/2;
if(ans==-1)
go(L,mid);
if(ans==-1)
go(mid,R);
}
}
int find_best(int n) {
for(int i=0;i<n;i++)
ANS[i]=ANS1[i]=-1;
if(n==1)
return 0;
for(int i=0;i<n;i++)
A[i]=1e9;
int mid=n/2;
go(0,mid);
if(ans==-1)
go(mid,n);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |