제출 #69475

#제출 시각아이디문제언어결과실행 시간메모리
69475Diuven커다란 상품 (IOI17_prize)C++14
20 / 100
54 ms2376 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; typedef vector<int> vi; const int MX=200010; bool up[MX]; int L[MX], R[MX], sum, n, ans; void my_ask(int i){ static set<int> S; if(S.find(i)!=S.end()) return; S.insert(i); vi now=ask(i); L[i]=now[0], R[i]=now[1]; } void search(int s, int e, int lc, int mc, int rc){ if(s>e || mc==0) return; assert(mc>=0); int m=(s+e)/2; for(int i=m; i<=e; i++){ my_ask(i); if(L[i]+R[i]==0){ ans=i; return; } if(L[i]+R[i]==sum){ search(s,m-1, lc, L[i]-(i-m)-lc, R[i]+i-m); search(i+1,e, L[i], R[i]-rc, rc); return; } } for(int i=m; i>=s; i--){ my_ask(i); if(L[i]+R[i]==0){ ans=i; return; } if(L[i]+R[i]==sum){ search(s,i-1, lc, L[i]-lc, R[i]); return; } } } void get(){ srand(time(NULL)); for(int i=0; i<20; i++){ int x=rand()%n; my_ask(x); sum=max(sum, L[x]+R[x]); } } int find_best(int _n){ n=_n; get(); ans=-1; search(0,n-1,0,sum,0); assert(ans>=0); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...