Submission #566358

#TimeUsernameProblemLanguageResultExecution timeMemory
566358lorenzoferrariThe Big Prize (IOI17_prize)C++17
96.65 / 100
70 ms916 KiB
#include <bits/stdc++.h> #include "prize.h" using namespace std; int mx_cnt; int answer = -1; map<int, array<int, 2>> memo; map<int, set<int>> found; array<int, 2> askme(int i) { array<int, 2> ans; if (memo.find(i) != memo.end()) { ans[0] = memo[i][0]; ans[1] = memo[i][1]; } else { auto v = ask(i); ans[0] = v[0]; ans[1] = v[1]; } memo[i] = {ans[0], ans[1]}; found[ans[0] + ans[1]].insert(i); if (ans[0] + ans[1] == 0) answer = i; return ans; } int count(int i) { return askme(i)[0] + askme(i)[1]; } bool makes_sense(int l, int r) { for (auto& ss : found) { if (ss.first == mx_cnt) continue; auto& s = ss.second; auto il = s.lower_bound(l); if (il == s.begin()) continue; il = prev(il); auto ir = s.lower_bound(r); if (ask(*ir)[0] - ask(*il)[0] == 0) return false; } return true; } void findall(int l, int r) { // assume t[l] = t[r] = v int cnt = askme(r)[0] - askme(l)[0]; if (cnt <= 0) return; if (answer != -1) return; int m = (l + r) / 2; int lm = m, rm = m; while (count(lm) != count(l)) { if (answer != -1) return; --lm; } while (count(rm) != count(l)) { if (answer != -1) return; ++rm; } findall(l, lm); findall(rm, r); } int find_best(int n) { srand(time(NULL)); for (int i = 0; i < 600; ++i) mx_cnt = max(mx_cnt, count(rand() % n)); int l = 0; while (count(l) != mx_cnt) ++l; int r = n-1; while (count(r) != mx_cnt) --r; findall(l, r); return answer; } #ifdef LORENZO int main() { cout << "insert n: "; fflush(stdout); int n; cin >> n; cout << "answer: " << find_best(n) << endl; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...