제출 #40219

#제출 시각아이디문제언어결과실행 시간메모리
40219jackyliuxx커다란 상품 (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); }

컴파일 시 표준 에러 (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...