QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#545034#7863. Parity GameXfJbUhpyzgaWWA 1ms3820kbC++142.5kb2024-09-02 22:00:242024-09-02 22:00:25

Judging History

你现在查看的是最新测评结果

  • [2024-09-02 22:00:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3820kb
  • [2024-09-02 22:00:24]
  • 提交

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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3820kb

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: 3536kb

input:

4 0
1 0 1 0
1 +
1

output:

Alice
1 *
1 *

result:

ok The player wins!

Test #3:

score: 0
Accepted
time: 1ms
memory: 3480kb

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: 1ms
memory: 3572kb

input:

3 0
1 1 1
1 +
1

output:

Bob
1 +

result:

ok The player wins!

Test #5:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

3 1
1 0 1
1 *
1

output:

Bob
1 *

result:

ok The player wins!

Test #6:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

3 0
1 0 1
1 *
1

output:

Bob
1 +

result:

ok The player wins!

Test #7:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

2 1
0 1
1

output:

Alice
1 +

result:

ok The player wins!

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 3540kb

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