#include "koala.h"
#include <cassert>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <functional>
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);
}
}
Compilation message
koala.cpp: In function 'void allValues(int, int, int*)':
koala.cpp:72:9: error: 'iota' was not declared in this scope
iota(Q, Q + N, 0);
^~~~
koala.cpp:72:9: note: suggested alternative: 'int'
iota(Q, Q + N, 0);
^~~~
int