제출 #1082338

#제출 시각아이디문제언어결과실행 시간메모리
1082338MMihalevThe Big Prize (IOI17_prize)C++14
90 / 100
51 ms2408 KiB
#include<iostream> #include<vector> #include<algorithm> #include<cmath> #include "prize.h" using namespace std; const int MAX_N=2e5+4; int asked[MAX_N][2]; bool used[MAX_N]; int qq; pair<int,int>query(int pos) { if(used[pos])return {asked[pos][0],asked[pos][1]}; if(qq>10000)while(1); used[pos]=1; qq++; auto ve=ask(pos); asked[pos][0]=ve[0]; asked[pos][1]=ve[1]; return {ve[0],ve[1]}; } int find_best(int n) { int prevpos=-1; int qq=500; int big=-1e9; while(qq--) { prevpos++; auto cur=query(prevpos); int all=cur.first+cur.second; if(all==0)return prevpos; big=max(big,all); } while(1) { prevpos++; auto cur=query(prevpos); int all=cur.first+cur.second; if(all==big) { int l=prevpos,r=n-1; while(l<=r) { int mid=(l+r)/2; auto cur2=query(mid); if(cur2==cur) { prevpos=mid; l=mid+1; } else r=mid-1; } } else { if(all==0)return prevpos; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...