QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#545149 | #7863. Parity Game | XfJbUhpyzgaW | WA | 0ms | 3616kb | C++14 | 3.0kb | 2024-09-02 23:04:30 | 2024-09-02 23:04:31 |
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;
if (x) exit(0);
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;
}
if (!out) 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) {
for (int i = 1; i <= n; i++) if (a[i]) exit(1);
exit(1);
write(1, "*");
}
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 (string op: {"+", "*"}) {
for (int i = 1; i < tn; i++) {
operate(i, op);
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, op);
good();
return 0;
}
}
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: 0
Wrong Answer
time: 0ms
memory: 3616kb
input:
4 1 0 1 0 1 1 *
output:
Alice 1 +
result:
wrong answer format Unexpected end of file - int32 expected