#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)
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)); //mx lollipop in the array
}
}
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 gi
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
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;
^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
4984 KB |
Output is correct |
2 |
Correct |
13 ms |
5060 KB |
Output is correct |
3 |
Correct |
14 ms |
5080 KB |
Output is correct |
4 |
Correct |
16 ms |
5288 KB |
Output is correct |
5 |
Correct |
11 ms |
5288 KB |
Output is correct |
6 |
Correct |
14 ms |
5288 KB |
Output is correct |
7 |
Correct |
9 ms |
5292 KB |
Output is correct |
8 |
Correct |
8 ms |
5292 KB |
Output is correct |
9 |
Correct |
13 ms |
5292 KB |
Output is correct |
10 |
Correct |
10 ms |
5304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
5304 KB |
Output is correct |
2 |
Correct |
14 ms |
5304 KB |
Output is correct |
3 |
Correct |
13 ms |
5304 KB |
Output is correct |
4 |
Correct |
11 ms |
5348 KB |
Output is correct |
5 |
Correct |
10 ms |
5348 KB |
Output is correct |
6 |
Correct |
13 ms |
5348 KB |
Output is correct |
7 |
Correct |
10 ms |
5348 KB |
Output is correct |
8 |
Correct |
9 ms |
5348 KB |
Output is correct |
9 |
Correct |
14 ms |
5348 KB |
Output is correct |
10 |
Correct |
16 ms |
5348 KB |
Output is correct |
11 |
Execution timed out |
1054 ms |
5348 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |