#include <bits/stdc++.h>
using namespace std;
#include "koala.h"
int R[105], B[105];
void __init__() { memset(R, 0, sizeof R); memset(B, 0, sizeof B); }
int minValue(int N, int W) {
__init__();
B[0] = 1;
playRound(B, R);
for (int i = 1; i < N; i++)
if (!R[i]) return i;
return 0;
}
int maxValue(int N, int W) {
vector<int> res(N);
iota(res.begin(), res.end(), 0);
while ((int) res.size() > 1) {
__init__();
for (auto i : res)
B[i] = W / res.size();
playRound(B, R);
int f = *max_element(R, R + N);
res.clear();
for (int i = 0; i < N; i++)
if (R[i] == f) res.push_back(i);
}
return res[0];
}
int greaterValue(int N, int W) {
int l = 0, r = sqrt(N * 2);
while (l <= r) {
int mid = (l + r) >> 1;
__init__();
B[0] = B[1] = mid;
playRound(B, R);
int c0 = R[0] > B[0], c1 = R[1] > B[1];
if (c0 ^ c1) {
if (c0) return 0;
if (c1) return 1;
}
if (c0) {
l = mid + 1;
} else {
r = mid - 1;
}
}
return 0;
}
int dp[105][105], ct[105][105], need[105];
inline int get_p(int N, int W, int LL, int RR) {
for (int p = 1; p <= W; p++) {
memset(dp, 0, sizeof dp);
memset(ct, 0, sizeof ct);
fill(need + 1, need + N + 1, 1);
for (int i = LL; i <= RR; i++)
need[i] = p + 1;
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= W; j++) {
dp[i][j] = dp[i - 1][j];
ct[i][j] = ct[i - 1][j];
if (j >= need[i] && dp[i][j] < dp[i - 1][j - need[i]] + i) {
dp[i][j] = dp[i - 1][j - need[i]] + i;
ct[i][j] = ct[i - 1][j - need[i]] + (i <= RR && i >= LL);
}
}
}
if (ct[N][W] > 0 && ct[N][W] < RR - LL + 1)
return p;
}
return 0;
}
void solve(int LL, int RR, int W, int T, int *P, vector<int> pos) {
if (LL == RR) {
assert((int) pos.size() == 1);
return P[pos[0]] = LL, (void) 0;
}
vector<int> lef, rig;
int f = T ? get_p(W, W, LL, RR) : W / pos.size();
__init__();
for (int i : pos) B[i] = f;
playRound(B, R);
for (int i : pos) {
if (R[i] > B[i])
rig.push_back(i);
else
lef.push_back(i);
}
int mid = LL + lef.size();
solve(LL, mid - 1, W, T, P, lef), solve(mid, RR, W, T, P, rig);
}
void allValues(int N, int W, int *P) {
vector<int> pos(N);
iota(pos.begin(), pos.end(), 0);
if (W == 2*N) {
solve(1, N, W, 0, P, pos);
} else {
solve(1, N, W, 1, P, pos);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
208 KB |
Output is correct |
2 |
Correct |
4 ms |
316 KB |
Output is correct |
3 |
Correct |
4 ms |
316 KB |
Output is correct |
4 |
Correct |
4 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
208 KB |
Output is correct |
2 |
Correct |
13 ms |
208 KB |
Output is correct |
3 |
Correct |
15 ms |
208 KB |
Output is correct |
4 |
Correct |
12 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
316 KB |
Output is correct |
2 |
Correct |
48 ms |
320 KB |
Output is correct |
3 |
Correct |
41 ms |
324 KB |
Output is correct |
4 |
Correct |
43 ms |
348 KB |
Output is correct |
5 |
Correct |
44 ms |
336 KB |
Output is correct |
6 |
Correct |
44 ms |
332 KB |
Output is correct |
7 |
Correct |
41 ms |
336 KB |
Output is correct |
8 |
Correct |
44 ms |
336 KB |
Output is correct |
9 |
Correct |
41 ms |
332 KB |
Output is correct |
10 |
Correct |
41 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
320 KB |
Output is correct |
2 |
Correct |
6 ms |
208 KB |
Output is correct |
3 |
Correct |
6 ms |
324 KB |
Output is correct |
4 |
Correct |
6 ms |
324 KB |
Output is correct |
5 |
Correct |
6 ms |
208 KB |
Output is correct |
6 |
Correct |
6 ms |
320 KB |
Output is correct |
7 |
Correct |
6 ms |
208 KB |
Output is correct |
8 |
Correct |
6 ms |
240 KB |
Output is correct |
9 |
Correct |
6 ms |
324 KB |
Output is correct |
10 |
Correct |
6 ms |
324 KB |
Output is correct |
11 |
Correct |
5 ms |
208 KB |
Output is correct |
12 |
Correct |
5 ms |
208 KB |
Output is correct |
13 |
Correct |
5 ms |
208 KB |
Output is correct |
14 |
Correct |
5 ms |
208 KB |
Output is correct |
15 |
Correct |
6 ms |
320 KB |
Output is correct |
16 |
Correct |
6 ms |
208 KB |
Output is correct |
17 |
Correct |
5 ms |
208 KB |
Output is correct |
18 |
Correct |
6 ms |
320 KB |
Output is correct |
19 |
Correct |
7 ms |
320 KB |
Output is correct |
20 |
Correct |
6 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
408 KB |
Output is correct |
2 |
Correct |
13 ms |
336 KB |
Output is correct |
3 |
Correct |
14 ms |
408 KB |
Output is correct |
4 |
Correct |
13 ms |
336 KB |
Output is correct |
5 |
Correct |
14 ms |
408 KB |
Output is correct |
6 |
Correct |
13 ms |
412 KB |
Output is correct |
7 |
Correct |
13 ms |
336 KB |
Output is correct |
8 |
Correct |
13 ms |
416 KB |
Output is correct |
9 |
Correct |
12 ms |
404 KB |
Output is correct |
10 |
Correct |
14 ms |
404 KB |
Output is correct |
11 |
Correct |
12 ms |
404 KB |
Output is correct |
12 |
Correct |
13 ms |
408 KB |
Output is correct |
13 |
Correct |
14 ms |
408 KB |
Output is correct |
14 |
Correct |
18 ms |
412 KB |
Output is correct |
15 |
Correct |
13 ms |
404 KB |
Output is correct |
16 |
Correct |
14 ms |
408 KB |
Output is correct |
17 |
Correct |
13 ms |
408 KB |
Output is correct |
18 |
Correct |
13 ms |
404 KB |
Output is correct |
19 |
Correct |
13 ms |
336 KB |
Output is correct |
20 |
Correct |
14 ms |
408 KB |
Output is correct |
21 |
Correct |
13 ms |
408 KB |
Output is correct |
22 |
Correct |
13 ms |
292 KB |
Output is correct |
23 |
Correct |
14 ms |
404 KB |
Output is correct |
24 |
Correct |
13 ms |
412 KB |
Output is correct |
25 |
Correct |
14 ms |
336 KB |
Output is correct |
26 |
Correct |
14 ms |
336 KB |
Output is correct |
27 |
Correct |
14 ms |
336 KB |
Output is correct |
28 |
Correct |
14 ms |
404 KB |
Output is correct |
29 |
Correct |
17 ms |
408 KB |
Output is correct |
30 |
Correct |
13 ms |
412 KB |
Output is correct |
31 |
Correct |
12 ms |
336 KB |
Output is correct |
32 |
Correct |
19 ms |
336 KB |
Output is correct |
33 |
Correct |
15 ms |
408 KB |
Output is correct |
34 |
Correct |
12 ms |
336 KB |
Output is correct |
35 |
Correct |
12 ms |
336 KB |
Output is correct |
36 |
Correct |
12 ms |
336 KB |
Output is correct |
37 |
Correct |
13 ms |
408 KB |
Output is correct |
38 |
Correct |
12 ms |
336 KB |
Output is correct |
39 |
Correct |
13 ms |
404 KB |
Output is correct |
40 |
Correct |
12 ms |
416 KB |
Output is correct |