1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #include <bits/stdc++.h> #define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i) #define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i) using namespace std; const int maxn = 2000 + 5; int a[3], T, n, t, k; bool dp[2][maxn][maxn][2][3];
inline int f(int x) { return (x + 3) % 3; }
void init() { dp[0][0][0][0][1] = dp[0][0][0][0][2] = 1; dp[0][0][0][1][0] = 1; FOR(t, 0, 2) FOR(i, 0, maxn) FOR(j, 0, maxn) FOR(r, 0, 2) FOR(v, 0, 3) { int s = r ? 1 : -1; bool &u = dp[t][i][j][r][v]; if (t) u |= !dp[t - 1][i][j][r ^ 1][f(v - s * 0)]; if (i) u |= !dp[t][i - 1][j][r ^ 1][f(v - s * 1)]; if (j) u |= !dp[t][i][j - 1][r ^ 1][f(v - s * 2)]; } }
int main() { init(); cin >> T; while (T--) { cin >> n; memset(a, 0, sizeof a); FOR(i, 0, n) { scanf("%d", &t); ++a[t % 3]; } if (dp[a[0] % 2][a[1]][a[2]][0][0]) puts("Balsa"); else puts("Koca"); } }
|