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 bug(x) cout << #x << " " << x << endl;
#define pii pair<int, int>
map<int, pii> mp;
pii query( int id ){
if( mp.count(id) ) return mp[id];
vector<int> resp = ask(id);
return (mp[id] = pii(resp[0], resp[1]));
}
int solve( int ini, int fim ){
if( query(ini).first + query(ini).second == 0 ) return ini;
if( query(fim).first + query(fim).second == 0 ) return fim;
if( query(fim).first == 0 || query(ini).second == 0 ) return -1;
if( query(ini) == query(fim) ) return (( query(ini).first + query(ini).second == 0 ) ? ini : -1 );
int mid = (ini + fim)/2;
if( rand()%2 ){
int aux = solve( ini, mid );
if( aux != -1 ) return aux;
if( fim - ini == 1 ) return solve( fim, fim );
return solve( mid, fim );
}
else{
if( fim - ini == 1 ) return solve( fim, fim );
int aux = solve( mid, fim );
if( aux != -1 ) return aux;
return solve( ini, mid );
}
}
int find_best(int n) {
srand(time(0));
return solve( 0, n - 1 );
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |