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 jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cerr << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
pii arr[200005];
pii query(int x)
{
if(~arr[x].F) return arr[x];
auto v=ask(x);
return arr[x]=MP(v[0],v[1]);
}
int search(int l,int r)
{
if(r-l<=1) return -1;
int m=l+r>>1;
pii a=query(l),t=query(m), b=query(r);
if(t==MP(0,0)) return m;
if((t.F==a.F)||!t.F) return search(m,r);
if((t.F==b.F)||!t.S) return search(l,m);
if(rand()%2)
{
int df=search(l,m);
if(~df) return df;
return search(m,r);
}
int df=search(m,r);
if(~df) return df;
return search(l,m);
}
int find_best(int n)
{
srand('I' + 'O' + 'I');
fill(arr,arr+n,MP(-1,-1));
if(query(0)==MP(0,0)) return 0;
if(query(n-1)==MP(0,0)) return n-1;
int ans = search(1,n-2);
return ans;
}
Compilation message (stderr)
prize.cpp: In function 'int search(int, int)':
prize.cpp:28:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m=l+r>>1;
~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |