QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#545022 | #7863. Parity Game | XfJbUhpyzgaW# | TL | 0ms | 3596kb | C++14 | 2.3kb | 2024-09-02 21:53:24 | 2024-09-02 21:53:25 |
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;
}
void bailan() {
if (n & 1) {
cout << "Bob" << endl;
read();
} else {
cout << "Alice" << endl;
}
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;
write(id, "+");
good();
} else {
evil();
}
} else {
if (check()) {
good();
} else {
evil();
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
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: 3568kb
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: 3520kb
input:
5 1 1 1 1 0 0 4 + 1 * 1
output:
Bob 1 * 1 *
result:
ok The player wins!
Test #4:
score: -100
Time Limit Exceeded
input:
3 0 1 1 1