제출 #67644

#제출 시각아이디문제언어결과실행 시간메모리
67644zscoder커다란 상품 (IOI17_prize)C++17
20 / 100
95 ms3040 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> ii; #define fi first #define se second #define pb push_back #define mp make_pair ii dp[442311]; int n; int totalquery; const int MX = 10000; ii query(int x) { if(x<0||x>=n) return mp(0,0); if(dp[x].fi>=0) return dp[x]; vector<int> a = ask(x); totalquery++; assert(totalquery<=MX); dp[x].fi=a[0]; dp[x].se=a[1]; return dp[x]; } vi global; vector<int> vec; int newmax; void solve(int l, int r) { if(l>r) return ; //later optimize by using count int mid=(l+r)>>1; ii cntl=query(vec[l]); if(cntl.fi+cntl.se<newmax){global.pb(vec[l]); solve(l+1,r); return ;} ii cntr=query(vec[r]); if(cntr.fi+cntr.se<newmax){global.pb(vec[r]); solve(l,r-1); return ;} ii tmp = query(vec[mid]); if(tmp.fi+tmp.se<newmax) { global.pb(vec[mid]); solve(l,mid-1); solve(mid+1,r); return ; } int cntleft = tmp.fi-cntl.fi; int cntright = tmp.se-cntr.se; if(cntleft) solve(l+1,mid-1); if(cntright) solve(mid+1,r-1); } int find_best(int _n) { n=_n; for(int i=0;i<n;i++) {dp[i]=mp(-1,-1);vec.pb(i);} while(vec.size()>1) { global.clear(); int C=555; C=min(C,int(vec.size())); newmax=0; for(int i=0;i<C;i++) { //cerr<<"QUERY : "<<query(vec[i]).fi<<' '<<query(vec[i]).se<<'\n'; newmax=max(newmax,query(vec[i]).fi+query(vec[i]).se); } //cerr<<"NEWMAX : "<<newmax<<'\n'; solve(0,int(vec.size())-1); vec=global; sort(vec.begin(),vec.end()); } return vec[0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...