Submission #82181

#TimeUsernameProblemLanguageResultExecution timeMemory
82181SecretAgent007The Big Prize (IOI17_prize)C++17
100 / 100
47 ms5456 KiB
#include <bits/stdc++.h> #include "prize.h" using namespace std; const int N = 200010; const int S = 1000; vector<int> memo[N]; inline vector<int> &query(int i) { if (memo[i].empty()) memo[i] = ask(i); return memo[i]; } inline int querysum(int i) { vector<int> &ret = query(i); return ret[0]+ret[1]; } int mx = 0, ans = -1; void solve(int l, int r, int k, int dl, int dr) { if (l > r) return; if (k == 0) return; int start = l, rem = dl, cnt = 0; for (int i = 1; i <= k; ++i) { if (ans != -1) break; int p = (l-1)+max(1, (r-l+2)/(k+1))*i; if (p >= l && p <= r) { if (querysum(p) == 0) { ans = p; break; } if (querysum(p) != mx) { ++cnt; continue; } int val = query(p)[0]; solve(start, p-1, val-rem, rem, query(p)[1]); start = p+1; rem = val; } } if (start <= r && ans == -1 && cnt < k) solve(start, r, k-(rem-dl), rem, dr); } int find_best(int n) { for (int i = 1; i < S; ++i) { int p = max(1, n/S)*i; if (p >= 0 && p < n) { if (querysum(p) == 0) return p; mx = max(mx, querysum(p)); } } int start = 0, rem = 0; for (int i = 1; i < S; ++i) { int p = max(1, n/S)*i; if (p >= 0 && p < n && querysum(p) == mx) { //querysum already computed int val = query(p)[0]; //val equals the total number of higher gift than lollipop on the left solve(start, p-1, val-rem, rem, query(p)[1]); if (ans != -1) return ans; start = p+1; rem = val; } } if (start <= n-1) solve(start, n-1,mx-rem, rem, 0); return ans; }

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:61:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if (start <= n-1)
     ^~
prize.cpp:64:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  return ans;
  ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...