Submission #1321646

#TimeUsernameProblemLanguageResultExecution timeMemory
1321646kasamchiThe Big Prize (IOI17_prize)C++20
97.95 / 100
18 ms5268 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> buf; vector<int> qry(int x) { if (buf[x].empty()) { return buf[x] = ask(x); } else { return buf[x]; } } int bcnt; vector<int> tar; void dfs(int l, int r, int cnt, int lp, int rs) { if (l == r) { tar.push_back(l); } else { int rm = l + (r - l) / 2, lm = rm; vector<int> res = qry(lm); while (res[0] + res[1] < bcnt) { tar.push_back(lm); lm--; if (lm < l) { break; } res = qry(lm); } int lc = res[0] - lp; if (lc > 0) { dfs(l, lm - 1, lc, lp, res[1]); } lm = rm; res = qry(lm); while (res[0] + res[1] < bcnt) { tar.push_back(lm); lm++; if (lm > r) { break; } res = qry(lm); } int rc = res[1] - rs; if (rc > 0) { dfs(lm + 1, r, rc, res[0], rs); } } } int find_best(int n) { buf.clear(), buf.resize(n); for (int i = 0; i < min(n, 447); i++) { vector<int> res = qry(i); bcnt = max(bcnt, res[0] + res[1]); } dfs(0, n - 1, bcnt, 0, 0); for (int x : tar) { vector<int> res = qry(x); if (res[0] + res[1] == 0) { return x; } } }

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:68:1: warning: control reaches end of non-void function [-Wreturn-type]
   68 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...