Submission #593336

#TimeUsernameProblemLanguageResultExecution timeMemory
593336blueThe Big Prize (IOI17_prize)C++17
20 / 100
73 ms5324 KiB
#include "prize.h" #include <vector> #include <iostream> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; #define sz(x) int(x.size()) const int mx = 200'000; int lim = 450; int n; int prizes = 0; //lollipops are not prizes vvi qr(mx, vi(0)); vi query(int i) { if(qr[i].empty()) qr[i] = ask(i); return qr[i]; } bool isprize(int i) { query(i); if(qr[i][0] + qr[i][1] != prizes) return 1; else return 0; } bool isdiamond(int i) { query(i); return qr[i][0] + qr[i][1] == 0; } void solve(int l, int r) { if(r < l) return; // cerr << "solve " << l << ' ' << r << '\n'; query(l); query(r); if(l == r) return; // cerr << "hello\n"; if(isprize(l)) { l++; solve(l, r); return; } if(isprize(r)) { r--; solve(l, r); return; } int m = (l+r)/2; query(m); // cerr << "check\n"; int ml = m, mr = m; while(isprize(ml)) ml--; query(ml); // cerr << "check\n"; // cerr << l << " : " << ml << '\n'; // cerr << sz(qr[l]) << ' ' << sz(qr[ml]) << '\n'; if(ml != l && qr[ml][0] - qr[l][0] >= 1) { // cerr << "call " << l+1 << ' ' << ml-1 << '\n'; solve(l+1, ml-1); } while(isprize(mr)) mr++; query(mr); // cerr << "check 5\n"; // cerr << r << " : " << mr << '\n'; if(mr != r && qr[r][0] - qr[mr][0] >= 1) solve(mr+1, r-1); } int find_best(int n_) { n = n_; if(n <= 5'000) { for(int i = 0; i < n; i++) { vi q = ask(i); if(q[0] + q[1] == 0) return i; } } // lim = 1; //the first thing must be a lollipop for(int i = 0; i < lim; i++) { vi qi = query(i); prizes = max(prizes, qi[0] + qi[1]); } // cerr << "prizes = " << prizes << '\n'; solve(lim, n-1); for(int i = 0; i < n; i++) if(!qr[i].empty()) if(qr[i][0] + qr[i][1] == 0) return i; while(1); return -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...