#include<bits/stdc++.h>
#ifndef LOCAL
#include "koala.h"
#endif // LOCAL
using namespace std;
#define pb push_back
#ifdef LOCAL
mt19937 rnd(51);
static int N, W;
static int P[105];
static int maxQueries = 3200;
static int numQueries;
static void runGame(int F);
static void grader();
int main() {
grader();
return 0;
}
void playRound(int *B, int *R) {
int i, j;
int S = 0;
for (i=0;i<N;++i) {
if ( !(B[i] >= 0 && B[i] <= W) ) {
printf("Invalid query.\n");
exit(0);
}
S += B[i];
}
if (S > W) {
printf("Invalid query.\n");
exit(0);
}
numQueries++;
if (numQueries > maxQueries) {
printf("Too many queries.\n");
exit(0);
}
int cache[2][205];
int num[2][205];
char taken[105][205];
for (i=0;i<205;++i) {
cache[1][i] = 0;
num[1][i] = 0;
}
for (i=0;i<N;++i) {
int v = B[i]+1;
int ii = i&1;
int o = ii^1;
for (j=0;j<=W;++j) {
cache[ii][j] = cache[o][j];
num[ii][j] = num[o][j];
taken[i][j] = 0;
}
for (j=W;j>=v;--j) {
int h = cache[o][j-v] + P[i];
int hn = num[o][j-v] + 1;
if (h > cache[ii][j] || (h == cache[ii][j] && hn > num[ii][j])) {
cache[ii][j] = h;
num[ii][j] = hn;
taken[i][j] = 1;
} else {
taken[i][j] = 0;
}
}
}
int cur = W;
for (i=N-1;i>=0;--i) {
R[i] = taken[i][cur] ? (B[i] + 1) : 0;
cur -= R[i];
}
}
#endif
int minValue(int n, int w) {
int b[n], r[n];
for (int i = 0; i < n; i++) b[i] = 0;
b[0] = 1;
playRound(b, r);
for (int i = 1; i < n; i++) {
if (r[i] == 0) {
return i;
}
}
return 0;
}
int maxValue(int n, int w) {
vector<int> arr(n);
iota(arr.begin(), arr.end(), 0);
while (arr.size() > 1) {
int sz = arr.size();
int can = w / sz;
int b[n], r[n];
for (int i = 0; i < n; i++) b[i] = 0;
for (auto to : arr) {
b[to] = can;
}
playRound(b, r);
vector<int> nw;
for (auto to : arr) {
if (b[to] == can && r[to] > can) {
nw.pb(to);
}
}
swap(arr, nw);
}
return arr[0];
}
int greaterValue(int n, int w) {
int l = 1, r = 9;
while (r - l > 1) {
int mid = (r + l) / 2;
int b[n], r1[n];
for (int i = 0; i < n; i++) b[i] = 0;
b[0] = b[1] = mid;
playRound(b, r1);
if (r1[0] > mid && r1[1] > mid) {
l = mid + 1;
} else if (r1[0] <= mid && r1[1] <= mid) {
r = mid - 1;
} else {
return r1[0] < mid;
}
}
int b[n], r1[n];
for (int i = 0; i < n; i++) b[i] = 0;
b[0] = b[1] = l;
playRound(b, r1);
return r1[0] < l;
}
void solve(int l, int r, vector<int> arr, int *p, bool t, int w, int n) {
if (l == r) {
p[arr[0]] = l;
return;
}
int mid;
if (t) {
mid = min((int)sqrt(2 * l), w / (r - l + 1));
} else {
mid = w / (r - l + 1);
}
int b[n], r1[n];
for (int i = 0; i < n; i++) b[i] = 0;
for (auto to : arr) {
b[to] = mid;
}
playRound(b, r1);
vector<int> sm, bg;
for (auto to : arr) {
if (b[to] == mid && r1[to] > mid) {
bg.pb(to);
} else {
sm.pb(to);
}
}
solve(l, l + (int)sm.size() - 1, sm, p, t, w, n);
solve(r - (int)bg.size() + 1, r, bg, p, t, w, n);
}
void allValues(int n, int w, int *p) {
vector<int> arr(n);
iota(arr.begin(), arr.end(), 0);
if (w == 2 * n) {
solve(1, n, arr, p, 0, w, n);
} else {
solve(1, n, arr, p, 1, w, n);
}
}
#ifdef LOCAL
static void runGame(int F) {
int i;
N = 100;
W = 100;
for (i=0;i<N;++i) {
P[i] = i + 1;
}
shuffle(P, P + N, rnd);
numQueries = 0;
if (F == 1) {
printf("%d\n", minValue(N, W));
} else if (F == 2) {
printf("%d\n", maxValue(N, W));
} else if (F == 3) {
int val = greaterValue(N, W);
assert(val == (P[0] < P[1]));
} else if (F == 4) {
int userP[105];
allValues(N, W, userP);
for (i=0;i<N;i++) {
printf("%d ",userP[i]);
assert(userP[i] == P[i]);
}
printf("\n");
}
printf("Made %d calls to playRound.\n", numQueries);
}
static void grader() {
int i;
int F, G;
scanf("%d %d",&F,&G);
for (i=0;i<G;i++) {
runGame(F);
}
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
208 KB |
Output is correct |
2 |
Correct |
5 ms |
208 KB |
Output is correct |
3 |
Correct |
4 ms |
208 KB |
Output is correct |
4 |
Correct |
4 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
320 KB |
Output is correct |
2 |
Correct |
13 ms |
316 KB |
Output is correct |
3 |
Correct |
13 ms |
208 KB |
Output is correct |
4 |
Correct |
11 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
296 KB |
Output is correct |
2 |
Correct |
57 ms |
324 KB |
Output is correct |
3 |
Correct |
47 ms |
332 KB |
Output is correct |
4 |
Correct |
50 ms |
320 KB |
Output is correct |
5 |
Correct |
56 ms |
324 KB |
Output is correct |
6 |
Correct |
56 ms |
324 KB |
Output is correct |
7 |
Correct |
50 ms |
328 KB |
Output is correct |
8 |
Correct |
49 ms |
312 KB |
Output is correct |
9 |
Correct |
49 ms |
320 KB |
Output is correct |
10 |
Correct |
48 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
208 KB |
Output is correct |
2 |
Correct |
6 ms |
208 KB |
Output is correct |
3 |
Correct |
7 ms |
312 KB |
Output is correct |
4 |
Correct |
6 ms |
208 KB |
Output is correct |
5 |
Correct |
6 ms |
324 KB |
Output is correct |
6 |
Correct |
6 ms |
208 KB |
Output is correct |
7 |
Correct |
6 ms |
208 KB |
Output is correct |
8 |
Correct |
6 ms |
336 KB |
Output is correct |
9 |
Correct |
6 ms |
208 KB |
Output is correct |
10 |
Correct |
6 ms |
208 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 |
208 KB |
Output is correct |
16 |
Correct |
6 ms |
328 KB |
Output is correct |
17 |
Correct |
6 ms |
208 KB |
Output is correct |
18 |
Correct |
6 ms |
208 KB |
Output is correct |
19 |
Correct |
6 ms |
208 KB |
Output is correct |
20 |
Correct |
6 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
208 KB |
Output is correct |
2 |
Correct |
5 ms |
208 KB |
Output is correct |
3 |
Correct |
4 ms |
320 KB |
Output is correct |
4 |
Correct |
4 ms |
356 KB |
Output is correct |
5 |
Correct |
3 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
328 KB |
Output is correct |
9 |
Correct |
3 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
3 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
3 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
4 ms |
336 KB |
Output is correct |
18 |
Correct |
3 ms |
336 KB |
Output is correct |
19 |
Correct |
3 ms |
208 KB |
Output is correct |
20 |
Correct |
3 ms |
336 KB |
Output is correct |
21 |
Correct |
3 ms |
336 KB |
Output is correct |
22 |
Correct |
3 ms |
336 KB |
Output is correct |
23 |
Correct |
3 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
208 KB |
Output is correct |
25 |
Correct |
3 ms |
208 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
3 ms |
336 KB |
Output is correct |
28 |
Correct |
3 ms |
208 KB |
Output is correct |
29 |
Correct |
3 ms |
208 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
3 ms |
208 KB |
Output is correct |
32 |
Correct |
3 ms |
336 KB |
Output is correct |
33 |
Correct |
3 ms |
208 KB |
Output is correct |
34 |
Correct |
3 ms |
336 KB |
Output is correct |
35 |
Correct |
4 ms |
336 KB |
Output is correct |
36 |
Correct |
3 ms |
336 KB |
Output is correct |
37 |
Correct |
3 ms |
336 KB |
Output is correct |
38 |
Correct |
3 ms |
336 KB |
Output is correct |
39 |
Correct |
3 ms |
208 KB |
Output is correct |
40 |
Correct |
3 ms |
336 KB |
Output is correct |