Submission #69945

#TimeUsernameProblemLanguageResultExecution timeMemory
69945DiuvenThe Big Prize (IOI17_prize)C++14
98.84 / 100
85 ms2240 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=-1; void my_ask(int i){ if(L[i]>=0) return; 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; 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 solve(){ int b=0; for(; b*b<=n; b++); vector<int> V; for(int ii=0; ii*b<n; ii++){ int i=ii*b; my_ask(i); if(i+1<n) my_ask(i+1); sum=max({sum, L[i]+R[i], L[i+1]+R[i+1]}); } V.push_back(0); for(int ii=0; ii*b<n; ii++){ for(int j=ii*b; j<min(n, ii*b+b); j++){ my_ask(j); if(L[j]+R[j]==sum){ V.push_back(j); break; } } } V.push_back(n); for(int i=0; i<(int)V.size()-1; i++){ int s=V[i], e=V[i+1]; my_ask(s); if(e<n) my_ask(e); int l=L[s], r=0; if(e<n) r = R[e] + (L[e]+R[e]<sum); search(s,e-1,l,sum-l-r,r); } } int find_best(int _n){ n=_n; for(int i=0; i<n; i++) L[i]=R[i]=-1; solve(); assert(ans>=0 && L[ans]==0 && R[ans]==0); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...