This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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) {
int val = query(p)[0];
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, n-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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |