Submission #40215

#TimeUsernameProblemLanguageResultExecution timeMemory
40215jackyliuxxThe Big Prize (IOI17_prize)C++14
97.41 / 100
32 ms2420 KiB
#include "prize.h" // #include <iostream> #include <map> using namespace std; map<int, map<int, pair<int, int>>> resmap; void resmap_push(int i, int lc, int rc) { resmap[lc + rc][i] = {lc, rc}; } int gogo(int fr, int to, int lc, int rc, int mxc) { // cout << "go " << fr << ' ' << to << endl; if (lc + rc == mxc) { return -1; } for (auto &rsmp : resmap) { auto &mp = rsmp.second; auto lb = mp.lower_bound(fr); auto ub = mp.upper_bound(to); pair<int, int> lres, rres; // cout << "check " << rsmp.first << endl; if (lb == mp.begin()) { // cout << "no lb" << endl; lres = {0, rsmp.first}; } else { lb--; // cout << "lb " << lb->first << endl; lres = lb->second; } if (ub == mp.end()) { // cout << "no ub" << endl; rres = {rsmp.first, 0}; } else { // cout << "ub " << ub->first << endl; rres = ub->second; } if (lres.first == rres.first) { // cout << "skip" << endl; return -1; } } int mid = (fr + to) / 2; int lto = mid, rfr = mid + 1; vector<int> res; 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); res = ask(mid); resmap_push(mid, res[0], res[1]); int c = res[0] + res[1]; if (c == 0) { return mid; } else if (c == mxc) { int lrc, rlc; if (mid == lto) { lrc = res[1]; rlc = res[0] + i; } else { lrc = res[1] + i; rlc = res[0]; } return max(gogo(fr, lto, lc, lrc, mxc), gogo(rfr, to, rlc, rc, mxc)); } } return -1; } int find_best(int n) { resmap.clear(); int mxc = 0; int lc = 0; for(int i = 0; i < n && i < 500; i++) { std::vector<int> res = ask(i); resmap_push(i, res[0], res[1]); lc = res[0]; if(res[0] + res[1] == 0) return i; if (res[0] + res[1] > mxc) { mxc = res[0] + res[1]; } } return gogo(0, n, 0, 0, mxc); }

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:78: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...