# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
253641 |
2020-07-28T13:27:59 Z |
atoiz |
Koala Game (APIO17_koala) |
C++14 |
|
95 ms |
512 KB |
#include "koala.h"
#include <cassert>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <functional>
#include <numeric>
using namespace std;
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORB(i, a, b) for (int i = a; i >= b; --i)
int A[100], B[100];
int minValue(int N, int W) {
// TODO: Implement Subtask 1 solution here.
// You may leave this function unmodified if you are not attempting this
// subtask.
FOR(i, 1, N - 1) A[i] = 0;
A[0] = 1;
playRound(A, B);
FOR(i, 0, N - 1) if (A[i] >= B[i]) return i;
assert(false);
return 0;
}
int maxValue(int N, int W) {
// TODO: Implement Subtask 2 solution here.
// You may leave this function unmodified if you are not attempting this
// subtask.
bool C[N];
FOR(i, 0, N - 1) C[i] = 1;
for (int _ = 0; _ < 4; ++_) {
int cnt = count(C, C + N, 1);
FOR(i, 0, N - 1) A[i] = C[i] * N / cnt;
playRound(A, B);
FOR(i, 0, N - 1) C[i] = C[i] && (A[i] < B[i]);
}
assert(count(C, C + N, 1) == 1);
FOR(i, 0, N - 1) if (C[i]) return i;
assert(false);
return 0;
}
int greaterValue(int N, int W) {
// TODO: Implement Subtask 3 solution here.
// You may leave this function unmodified if you are not attempting this
// subtask.
int lo = 1, hi = 7;
while (true) {
assert(lo <= hi);
int mid = (lo + hi) >> 1;
FOR(i, 2, N - 1) A[i] = 0;
A[0] = A[1] = mid + (mid == 7);
playRound(A, B);
if ((A[0] < B[0]) != (A[1] < B[1])) return A[1] < B[1];
if (A[0] < B[0]) lo = mid + 1;
else hi = mid - 1;
}
assert(false);
return 0;
}
void allValues(int N, int W, int *P) {
if (W == 2*N) {
// TODO: Implement Subtask 4 solution here.
// You may leave this block unmodified if you are not attempting this
// subtask.
int Q[N], T[N];
iota(Q, Q + N, 0);
auto comp = [&](int i, int j) {
memset(A, 0, sizeof A);
A[i] = A[j] = W / 2;
playRound(A, B);
return A[i] >= B[i];
};
function<void(int, int)> msort = [&](int l, int r) {
if (l == r) return;
int m = (l + r) >> 1;
msort(l, m), msort(m + 1, r);
memcpy(T + l, Q + l, sizeof(Q[0]) * (r - l + 1));
for (int i = l, j = m + 1, k = l; k <= r; ++k) {
Q[k] = (j > r || (i <= m && comp(T[i], T[j]))) ? T[i++] : T[j++];
}
};
msort(0, N - 1);
FOR(i, 0, N - 1) P[Q[i]] = i + 1;
} else {
// TODO: Implement Subtask 5 solution here.
// You may leave this block unmodified if you are not attempting this
// subtask.
int Q[N + 1];
FOR(i, 0, N - 1) P[i] = 0;
memset(Q, -1, sizeof Q);
FOR(x, 1, 50) {
memset(A, 0, sizeof A);
FOR(y, 1, x - 1) A[Q[y]] = 1;
int cur = x;
FOR(i, 0, N - 1) if (!A[i] && cur) A[i] = 1, --cur;
playRound(A, B);
FOR(i, 0, N - 1) if (!P[i] && A[i] >= B[i]) P[i] = x, Q[x] = i;
assert(~Q[x]);
FOR(i, 0, N - 1) if (P[i] == x) assert(Q[x] == i);
}
FOR(x, 51, 67) {
FOR(i, 0, N - 1) A[i] = (P[i] < 100 - x);
playRound(A, B);
FOR(i, 0, N - 1) if (!P[i] && A[i] >= B[i]) P[i] = x, Q[x] = i;
assert(~Q[x]);
FOR(i, 0, N - 1) if (P[i] == x) assert(Q[x] == i);
}
memset(A, 0, sizeof A);
FOR(i, 0, N - 1) if (!P[i] || P[i] > 50) A[i] = 2;
playRound(A, B);
int cur = 68;
FOR(i, 0, N - 1) if (!P[i] && A[i] >= B[i]) P[i] = cur, Q[cur] = i, ++cur;
assert(cur == 76);
auto get = [&](int a, int b, int c, int x, int f) {
FOR(i, 0, N - 1) {
if (!P[i]) A[i] = f;
else if (P[i] <= c) A[i] = 0;
else if (P[i] <= b) A[i] = 1;
else if (P[i] <= a) A[i] = 2;
else A[i] = 3;
}
playRound(A, B);
FOR(i, 0, N - 1) if (!P[i] && A[i] >= B[i]) P[i] = x, Q[x] = i;
assert(~Q[x]);
FOR(i, 0, N - 1) if (P[i] == x) assert(Q[x] == i);
};
// Why .....
// Just why ..... T_T
get(100, 52, 49, 76, 2);
get(100, 54, 50, 77, 2);
get(100, 56, 50, 78, 2);
get(100, 58, 51, 79, 2);
get(100, 60, 51, 80, 2);
cur = 81;
FOR(i, 0, N - 1) if (!P[i]) P[i] = cur, Q[cur] = i, ++cur;
FOR(x, 68, 75) P[Q[x]] = 0, Q[x] = -1;
get(75, 64, 62, 68, 2);
get(75, 65, 62, 69, 2);
get(75, 67, 59, 70, 2);
get(75, 70, 58, 71, 2);
get(77, 71, 54, 72, 2);
get(78, 72, 52, 73, 2);
get(79, 73, 50, 74, 2);
FOR(i, 0, N - 1) if (!P[i]) P[i] = 75, Q[75] = i;
assert(~Q[75]);
FOR(i, 0, N - 1) if (P[i] == 75) assert(Q[75] == i);
FOR(x, 81, 100) P[Q[x]] = 0, Q[x] = -1;
get(100, 62, 52, 81, 2);
get(100, 64, 53, 82, 2);
get(100, 66, 54, 83, 2);
get(100, 68, 54, 84, 2);
get(100, 70, 55, 85, 2);
get(100, 72, 56, 86, 2);
get(100, 74, 56, 87, 2);
get(100, 76, 57, 88, 2);
get(100, 78, 58, 89, 2);
get(100, 80, 58, 90, 2);
get(100, 82, 59, 91, 2);
get(100, 84, 60, 92, 2);
get(100, 86, 60, 93, 2);
get(100, 88, 61, 94, 2);
get(100, 90, 62, 95, 2);
get(100, 92, 62, 96, 2);
get(100, 94, 63, 97, 2);
get(100, 96, 64, 98, 2);
get(100, 98, 64, 99, 2);
FOR(i, 0, N - 1) if (!P[i]) P[i] = 100, Q[100] = i;
assert(~Q[100]);
FOR(i, 0, N - 1) if (P[i] == 100) assert(Q[100] == i);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
384 KB |
Output is correct |
2 |
Correct |
17 ms |
384 KB |
Output is correct |
3 |
Correct |
17 ms |
384 KB |
Output is correct |
4 |
Correct |
17 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
384 KB |
Output is correct |
2 |
Correct |
95 ms |
384 KB |
Output is correct |
3 |
Correct |
84 ms |
384 KB |
Output is correct |
4 |
Correct |
84 ms |
512 KB |
Output is correct |
5 |
Correct |
84 ms |
384 KB |
Output is correct |
6 |
Correct |
87 ms |
384 KB |
Output is correct |
7 |
Correct |
86 ms |
384 KB |
Output is correct |
8 |
Correct |
86 ms |
384 KB |
Output is correct |
9 |
Correct |
83 ms |
384 KB |
Output is correct |
10 |
Correct |
85 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
384 KB |
Output is correct |
2 |
Correct |
46 ms |
384 KB |
Output is correct |
3 |
Correct |
44 ms |
384 KB |
Output is correct |
4 |
Correct |
43 ms |
384 KB |
Output is correct |
5 |
Correct |
42 ms |
384 KB |
Output is correct |
6 |
Correct |
43 ms |
384 KB |
Output is correct |
7 |
Correct |
42 ms |
384 KB |
Output is correct |
8 |
Correct |
42 ms |
384 KB |
Output is correct |
9 |
Correct |
42 ms |
384 KB |
Output is correct |
10 |
Correct |
41 ms |
384 KB |
Output is correct |
11 |
Correct |
43 ms |
384 KB |
Output is correct |
12 |
Correct |
26 ms |
512 KB |
Output is correct |
13 |
Correct |
42 ms |
384 KB |
Output is correct |
14 |
Correct |
39 ms |
384 KB |
Output is correct |
15 |
Correct |
39 ms |
384 KB |
Output is correct |
16 |
Correct |
37 ms |
384 KB |
Output is correct |
17 |
Correct |
38 ms |
376 KB |
Output is correct |
18 |
Correct |
39 ms |
384 KB |
Output is correct |
19 |
Correct |
38 ms |
384 KB |
Output is correct |
20 |
Correct |
40 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
288 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
6 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
4 ms |
384 KB |
Output is correct |
37 |
Correct |
4 ms |
384 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
4 ms |
384 KB |
Output is correct |
40 |
Correct |
4 ms |
384 KB |
Output is correct |