Submission #40219

#TimeUsernameProblemLanguageResultExecution timeMemory
40219jackyliuxxThe Big Prize (IOI17_prize)C++14
97.42 / 100
29 ms2420 KiB
#include "prize.h" #include <map> #include <iostream> using namespace std; map<int, pair<int, int>> resmp; pair<int, int> myask(int i) { if (resmp.find(i) == resmp.end()) { auto r = ask(i); resmp[i] = {r[0], r[1]}; } return resmp[i]; } int gogo(int fr, int to, int lc, int rc, int mxc) { if (lc + rc == mxc) { return -1; } int mid = (fr + to) / 2; int lto = mid, rfr = mid + 1; int n = to - fr; for (int i = 0; i < n; i++) { if (i & 1) { mid -= i; } else { mid += i; } lto = min(lto, mid); rfr = max(rfr, mid + 1); auto res = myask(mid); int c = res.first + res.second; if (c == 0) { return mid; } else if (c == mxc) { int lrc, rlc; if (mid == lto) { lrc = res.second; rlc = res.first + i; } else { lrc = res.second + i; rlc = res.first; } int lrt = gogo(fr, lto, lc, lrc, mxc); if (lrt != -1) { return lrt; } else { return gogo(rfr, to, rlc, rc, mxc); } } } return -1; } int find_best(int n) { resmp.clear(); int mxc = 0; int lc = 0; for(int i = 0; i < n && i < 500; i++) { auto res = myask(i); lc = res.first; if(res.first + res.second == 0) return i; if (res.first + res.second > mxc) { mxc = res.first + res.second; } } return gogo(0, n, 0, 0, mxc); }

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:58:9: warning: variable 'lc' set but not used [-Wunused-but-set-variable]
     int lc = 0;
         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...