QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#545026 | #7863. Parity Game | XfJbUhpyzgaW# | WA | 1ms | 3848kb | C++14 | 2.5kb | 2024-09-02 21:55:19 | 2024-09-02 21:55:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int n, t, a[N], ta[N];
void operate(int p, string op) {
if (op == "+") a[p] ^= a[p + 1];
else a[p] &= a[p + 1];
for (int i = p + 1; i < n; i++) a[i] = a[i + 1];
n--;
}
void read() {
int x;
string op;
cin >> x >> op;
operate(x, op);
}
void write(int x, string op) {
operate(x, op);
cout << x << " " << op << endl << flush;
}
void bailan() {
if (n & 1) {
cout << "Bob" << endl << flush;
read();
} else {
cout << "Alice" << endl << flush;
}
while (n > 2) {
write(1, "*");
read();
}
write(1, a[1] & a[2] ? "+" : "*");
exit(0);
}
bool check() {
assert(n & 1);
int flag = 0, cnt1 = 0, cnt0 = 0;
for (int i = 1; i <= n; i++) {
if (a[i] == 0)
cnt1 += flag, cnt0++, flag = 0;
else
flag ^= 1;
}
cnt1 += flag;
return cnt1 > cnt0;
}
void good() {
while (n >= 2) {
read();
for (int i = 1; i < n; i++) if (a[i] != a[i + 1])
write(i, "+");
}
}
void evil() {
while (n >= 2) {
bool out = 0;
for (int i = 1; i < n; i++) if (a[i] && a[i + 1]) {
out = 1;
write(i, "+");
break;
}
if (!out) {
for (int i = 1; i < n; i++) if (a[i] != a[i + 1]) {
out = 1;
write(i, "*");
}
}
read();
}
}
int main() {
cin >> n >> t;
for (int i = 1; i <= n; i++) cin >> a[i], ta[i] = a[i];
t ^= n & 1;
if (!t) bailan();
int id = 0, tn = n;
if (tn % 2 == 0) {
for (int i = 1; i < tn; i++) {
operate(i, "+");
if (check()) {
n = tn;
for (int j = 1; j <= tn; j++) a[j] = ta[j];
id = i;
break;
}
n = tn;
for (int j = 1; j <= tn; j++) a[j] = ta[j];
}
if (id) {
cout << "Alice" << endl << flush;
write(id, "+");
good();
} else {
cout << "Bob" << endl << flush;
evil();
}
} else {
if (check()) {
cout << "Bob" << endl << flush;
good();
} else {
cout << "Alice" << endl << flush;
evil();
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3496kb
input:
4 1 0 1 0 1 1 * 1
output:
Alice 1 + 1 +
result:
ok The player wins!
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
4 0 1 0 1 0 1 + 1
output:
Alice 1 * 1 *
result:
ok The player wins!
Test #3:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
5 1 1 1 1 0 0 4 + 1 * 1
output:
Bob 1 * 1 *
result:
ok The player wins!
Test #4:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
3 0 1 1 1 1 + 1
output:
Bob 1 +
result:
ok The player wins!
Test #5:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
3 1 1 0 1 1 * 1
output:
Bob 1 *
result:
ok The player wins!
Test #6:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
3 0 1 0 1 1 * 1
output:
Bob 1 +
result:
ok The player wins!
Test #7:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
2 1 0 1 1
output:
Alice 1 +
result:
ok The player wins!
Test #8:
score: -100
Wrong Answer
time: 1ms
memory: 3648kb
input:
499 0 0 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1 1 1 0 1 0 ...
output:
Alice 2 + 2 + 2 + 4 + 6 + 10 + 12 + 12 + 14 + 14 + 16 + 20 + 20 + 20 + 20 + 22 + 22 + 24 + 24 + 26 + 26 + 26 + 28 + 28 + 28 + 28 + 30 + 30 + 30 + 32 + 32 + 34 + 36 + 38 + 40 + 40 + 48 + 48 + 48 + 48 + 48 + 52 + 54 + 54 + 54 + 58 + 58 + 58 + 60 + 60 + 62 + 66 + 68 + 70 + 70 + 72 + 74 + 76 + 76 + 78 +...
result:
wrong answer invalid operation