Submission #316334

#TimeUsernameProblemLanguageResultExecution timeMemory
316334nikatamlianiThe Big Prize (IOI17_prize)C++14
94.67 / 100
61 ms5508 KiB
#include <bits/stdc++.h> using namespace std; #include "prize.h" vector < vector < int > > memo; vector < int > memo_ask(int x) { if(!memo[x].empty()) return memo[x]; return memo[x] = ask(x); } int find_best(int n) { int next = -1, at_most = min(472, n - 1); const int BLOCK_SIZE = 472; vector < int > bad(2); memo.resize(n); int limit = 30, cnt = 0; for(int i = 0; i <= at_most; ++i) { vector < int > cur = memo_ask(i); if(bad[0] + bad[1] <= cur[0] + cur[1]) bad = cur; if(cur[0] == 0 && cur[1] == 0) return i; } for(int i = 0; i <= at_most; ++i) { if(bad[0] + bad[1] != memo_ask(i)[0] + memo_ask(i)[1]) { ++cnt; } } vector < int > bad0 = bad, bad1(2); if(cnt > limit) { for(int i = 0; i <= at_most; ++i) { if(bad[0] + bad[1] != memo_ask(i)[0] + memo_ask(i)[1]) { bad1 = memo_ask(i); } } } for(int i = at_most + 1; i < n; i = next + 1) { int l = i, r = n - 1; next = -1; vector < int > t = memo_ask(i); if(t[0] + t[1] != bad0[0] + bad0[1]) { ++cnt; if(cnt <= limit) { if(bad1[0] + bad1[1] <= t[0] + t[1]) { bad1 = t; } } else { bad1[0]++; bad1[1]--; } next = i; if(t[0] == 0 && t[1] == 0) return i; continue; } bad0 = t; int maybe = i + BLOCK_SIZE; if(maybe < n) { if(memo_ask(maybe) == bad0 || memo_ask(maybe) == bad1) { next = maybe; continue; } } if(maybe < n) r = maybe - 1; while(r >= l) { int m = l + r >> 1; if(memo_ask(m) == bad0) { next = m; l = m + 1; } else { r = m - 1; } } assert(next >= i); } }

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:60:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |             int m = l + r >> 1;
      |                     ~~^~~
prize.cpp:12:25: warning: control reaches end of non-void function [-Wreturn-type]
   12 |     vector < int > bad(2);
      |                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...