제출 #40218

#제출 시각아이디문제언어결과실행 시간메모리
40218jackyliuxx커다란 상품 (IOI17_prize)C++14
97.41 / 100
22 ms2020 KiB
#include "prize.h" #include <iostream> using namespace std; 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; 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); 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]; } 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) { int mxc = 0; for(int i = 0; i < n && i < 500; i++) { std::vector<int> res = ask(i); 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); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...