Submission #728122

#TimeUsernameProblemLanguageResultExecution timeMemory
728122nguyentunglamThe Big Prize (IOI17_prize)C++17
100 / 100
71 ms5308 KiB
#include<bits/stdc++.h> using namespace std; #include "prize.h" //mt19937 rng(172831923); ////mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //int rnd(int l, int r) { // return l + rng() % (r - l + 1); //} const int N = 2e5 + 10; vector<int> ans[N]; int worst; int check(int i, int j) { if (ans[i].empty()) ans[i] = ask(i); if (ans[j].empty()) ans[j] = ask(j); if (ans[j][0] + ans[j][1] != worst) return 2; int tmp = ans[i][1] + ans[j][0] - worst; return tmp > 0; } int find_best(int n) { int T = max(1, n / 785); for(int i = 0; i < n; i += T) { ans[i] = ask(i); worst = max(worst, ans[i][0] + ans[i][1]); } for(int i = 1; i < n; i++) if (i % T) { if (ans[i].empty()) ans[i] = ask(i); if (ans[i][0] + ans[i][1] != worst) continue; int l = i, r = n - 1; for(int j = T; j < n; j += T) if (j > i) { if (check(i, j)) { r = j; break; } l = j; } int last = l; while (l <= r) { int mid = l + r >> 1; int tmp = check(i, mid); if (!tmp) { last = mid; l = mid + 1; } else r = mid - 1; } // cout << i << " " << last << endl; i = last; } for(int i = 0; i < n; i++) if (!ans[i].empty() && ans[i][0] + ans[i][1] == 0) { return i; } return 0; }

Compilation message (stderr)

prize.cpp: In function 'int check(int, int)':
prize.cpp:14:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   14 |     if (ans[i].empty()) ans[i] = ask(i); if (ans[j].empty()) ans[j] = ask(j);
      |     ^~
prize.cpp:14:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   14 |     if (ans[i].empty()) ans[i] = ask(i); if (ans[j].empty()) ans[j] = ask(j);
      |                                          ^~
prize.cpp: In function 'int find_best(int)':
prize.cpp:42:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |             int mid = l + r >> 1;
      |                       ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...