# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104050 | RockyB | The Big Prize (IOI17_prize) | C++17 | 0 ms | 0 KiB |
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),b=query(r),t=query(m);
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(time('I' + 'O' + 'I'));
fill(arr,arr+n,MP(-1,-1));
int ans = search(0,n-1);
if (~ans) return ans;
if(query(0)==MP(0,0)) return 0;
if(query(n-1)==MP(0,0)) return n-1;
}