Submission #1113541

#TimeUsernameProblemLanguageResultExecution timeMemory
1113541epicci23The Big Prize (IOI17_prize)C++17
90 / 100
180 ms2400 KiB
#include "bits/stdc++.h" #include "prize.h" //#define int long long #define all(v) v.begin() , v.end() #define sz(a) (int)a.size() using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline int rand(int l,int r){ return l + rng() % (r-l+1); } const int BL = 500; int suf = -1; vector<int> Cache={-1,-1}; map<int,vector<int>> dp; vector<int> Ask(int i){ if( dp.count(i) ) return dp[i]; return dp[i] = ask(i); } int ask_all(int l,int r){ for(int i = l; i <= r; i++){ vector<int> x = Ask(i); if(x[0] + x[1] == 0) return i; if(x[1] == suf) Cache = x; else suf--; } return -23; } int Learn(int l,int r){ if(l>r) return -1; if(l==r){ auto u = Ask(l); if(u[0] + u[1] == 0) return l; if(u[1] == suf) Cache=u; else suf--; return -1; } auto X = Ask(r); if(X[0] + X[1] == 0) return r; if(X[1] == suf) return -1; if(l+BL+1<r){ auto u = Ask(l + BL); if(u[0]+u[1]==0) return l+BL; if(u[1] == suf) return Learn(l+BL+1,r-1); int hm = Learn(l,l+BL-1); if(hm != -1) return hm; if(u[1] == suf) Cache = u; else suf--; if(X[1] == suf - ( Cache[0] + Cache[1] > X[0] + X[1] ) ) return -1; int hm2 = Learn(l+BL+1,r-1); if(hm2 != -1) return hm2; if(X[1] == suf) Cache = X; else suf--; return -1; } int mid = (l+r) / 2; auto u = Ask(mid); if(u[0] + u[1] == 0) return mid; if(u[1] == suf) return Learn(mid + 1,r - 1); int lf = Learn(l,mid - 1); if(lf != -1) return lf; if(u[1]==suf) Cache = u; else suf--; if(X[1] == suf - ( Cache[0] + Cache[1] > X[0] + X[1] ) ) return -1; int hm = Learn( mid + 1, r - 1 ); if(hm != -1) return hm; if(X[1] == suf) Cache = X; else suf--; return -1; } int find_best(int n){ if(n <= 1000) return ask_all(0, n - 1); int art = 0; for(int i = 0; i <= 500; i++){ if(art == 5) return Learn(i, n - 1); vector<int> x = Ask(i); if(x[0] + x[1] == 0) return i; if(x[0] + x[1] > Cache[0] + Cache[1]) art++; if(x[0] + x[1] >= Cache[0] + Cache[1]){ Cache = x; suf = Cache[1]; } else suf--; } return Learn(501, n - 1 ); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...