Submission #1256089

#TimeUsernameProblemLanguageResultExecution timeMemory
1256089gelastropodThe Big Prize (IOI17_prize)C++20
100 / 100
12 ms1944 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; int ans = -1, lolpop = 0; vector<pair<int, int>> cache; pair<int, int> qry(int i) { if (cache[i].first == -1) { auto j = ask(i); cache[i] = {j[0], j[1]}; if (j[0] + j[1] == 0) ans = i; } return cache[i]; } void dnc(int l, int r, int numl, int numr) { int m = (l + r) / 2; for (int i = 0; i <= r - l; i++) { int lbound = m - i / 2, rbound = m + (i + 1) / 2, truem = (i % 2 ? rbound : lbound); auto j = qry(truem); if (ans != -1) return; if (j.first + j.second == lolpop) { if (i % 2) { if (j.second > numr) dnc(rbound + 1, r, j.first, numr); if (j.first - i > numl) dnc(l, lbound - 1, numl, j.second + i); } else { if (j.first > numl) dnc(l, lbound - 1, numl, j.second); if (j.second - i > numr) dnc(rbound + 1, r, j.first + i, numr); } return; } } } int find_best(int n) { cache.resize(n, {-1, -1}); int firstl = 0; for (int i = 0; i < min(n, 474) && lolpop <= 26; i++) { auto j = qry(i); if (ans != -1) return ans; if (j.first + j.second > lolpop) { lolpop = j.first + j.second; firstl = i; } } dnc(firstl, n - 1, firstl, 0); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...