QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#545051 | #7863. Parity Game | XfJbUhpyzgaW | RE | 2ms | 3624kb | C++14 | 2.8kb | 2024-09-02 22:20:55 | 2024-09-02 22:20:55 |
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();
bool out = 0;
for (int i = 1; i < n; i++) if (!a[i] && !a[i + 1]) {
write(i, "+");
out = 1;
break;
}
for (int i = 1; i < n; i++) if (a[i] != a[i + 1]) {
write(i, "+");
out = 1;
break;
}
if (!out)
write(1, "*");
}
}
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, "*");
break;
}
}
if (!out) {
cout << "evil is dead\n";
exit(0);
}
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: 3560kb
input:
4 1 0 1 0 1 1 * 1
output:
Alice 1 + 1 +
result:
ok The player wins!
Test #2:
score: 0
Accepted
time: 1ms
memory: 3556kb
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: 3616kb
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: 3612kb
input:
3 0 1 1 1 1 + 1
output:
Bob 1 +
result:
ok The player wins!
Test #5:
score: 0
Accepted
time: 0ms
memory: 3616kb
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: 3624kb
input:
2 1 0 1 1
output:
Alice 1 +
result:
ok The player wins!
Test #8:
score: 0
Accepted
time: 2ms
memory: 3560kb
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:
ok The player wins!
Test #9:
score: -100
Runtime Error
input:
499 0 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 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 0 1 ...
output:
Bob 1 + 2 + 1 + 2 + 3 + 2 + 10 + 6 + 1 + 5 + 7 + 12 + 18 + 14 + 14 + 15 + 17 + 16 + 17 + 17 + 21 + 17 + 18 + 27 + 22 + 22 + 17 + 21 + 24 + 21 + 29 + 28 + 30 + 30 + 31 + 30 + 30 + 32 + 31 + 32 + 41 + 34 + 29 + 35 + 31 + 40 + 34 + 41 + 36 + 37 + 38 + 40 + 48 + 30 + 44 + 52 + 50 + 50 + 58 + 36 + 39 + 5...