QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#297919#7863. Parity Gameucup-team902#RE 1ms3748kbC++173.6kb2024-01-05 13:30:562024-01-05 13:30:57

Judging History

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

  • [2024-01-05 13:30:57]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3748kb
  • [2024-01-05 13:30:56]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

const int N = 505;

int n, t;
int a[N];

int winning[2] = {0, 1};
string name[2] = {"Alice", "Bob"};

inline void maintain(int x, int op){
    a[x] = (op ? (a[x] ^ a[x + 1]) : (a[x] & a[x + 1]));
    for(int i = x + 1; i < n; ++i){
        a[i] = a[i + 1];
    }
    --n;
}

inline void answer(int x, int op){
    cout << x << ' ' << (op ? '+' : '*') << endl;
    fflush(stdout);
    maintain(x, op);
}

inline void read(){
    int y; cin >> y;
    char c; cin >> c;
    while(c == ' ') cin >> c;
    maintain(y, c == '+');
    // maintain(1, rand() % 2);
}

inline void work1(int me){
    cout << name[me] << endl;
    fflush(stdout);
    int player = 0;
    while(n != 1){
        if(player == me){
            if(a[1] == 1 && a[2] == 1){
                answer(1, 1);
            }
            else {
                answer(1, 0);
            }
        }
        else{
            read();
        }
        player ^= 1;
    }
    assert(a[1] == winning[me]);
}

inline void work2(int me){
    cout << name[me] << endl;
    fflush(stdout);
    int player = 0;
    while(n != 1){
        if(player == me){
            bool flag = 0;
            for(int i = 1; i < n; ++i){
                if(a[i] != a[i + 1]){
                    answer(i, 1);
                    flag = 1;
                    break;
                }
            }
            if(!flag){
                assert(a[1] == 1);
                answer(1, 0);
                flag = 1;
            }
        }
        else{
            read();
        }
        player ^= 1;
    }
    assert(a[1] == winning[me]);
}

inline void work3(int me){
    cout << name[me] << endl;
    fflush(stdout);
    int player = 0;
    while(n != 1){
        if(player == me){
            bool flag = 0;
            for(int i = 1; i < n; ++i){
                if(a[i] == 1 && a[i + 1] == 1){
                    answer(i, 1);
                    flag = 1;
                    break;
                }
            }
            if(!flag){
                for(int i = 1; i < n; ++i){
                    if(a[i] != a[i + 1]){
                        answer(i, 0);
                        flag = 1;
                        break;
                    }
                }
            }
            if(!flag){
                answer(1, 0);
            }
        }
        else{
            read();
        }
        player ^= 1;
    }
    assert(a[1] == winning[me]);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // auto seed = time(0);
    // srand(seed);
    // cerr << seed << endl;
    // n = rand() % 10 + 2;
    // t = rand() % 2;
    // for(int i = 1; i <= n; ++i){
    //     a[i] = rand() % 2;
    // }
    // cerr << n << " " << t << endl;
    // for(int i = 1; i <= n; ++i){
    //     cerr << a[i] << " ";
    // }
    // cerr << endl;
    cin >> n >> t;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    int lstplayer = n & 1;
    winning[0] ^= t;
    winning[1] ^= t;
    if(winning[lstplayer] == 0){
        work1(lstplayer);
    }
    else{
        int cnt[2] = {0};
        for(int i = 1; i <= n; ++i){
            if(a[i] == 0){
                cnt[0]++;
            }
            else{
                int j = i;
                while(j < n && a[j + 1] == 1) ++j;
                if(j - i + 1 & 1){
                    cnt[1]++;
                }
            }
        }
        if(cnt[1] + (lstplayer == 0) > cnt[0]) work2(lstplayer);
        else work3(lstplayer ^ 1);
    }
    return 0;
}

详细

Test #1:

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

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

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

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

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: 0ms
memory: 3488kb

input:

3 0
1 0 1
1 *
1

output:

Bob
1 +

result:

ok The player wins!

Test #7:

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

input:

2 1
0 1
1

output:

Alice
1 +

result:

ok The player wins!

Test #8:

score: -100
Runtime Error

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:

Bob
2 +
2 +
2 +
1 +
1 +
1 +
3 +
2 +
1 +
1 +
3 +
2 +
1 +
1 +
1 +
1 +
4 +
3 +
2 +
1 +
1 +
1 +
2 +
1 +
1 +
1 +
1 +
1 +
1 +
4 +
3 +
2 +
1 +
1 +
1 +
1 +
5 +
4 +
3 +
2 +
1 +
1 +
1 +
1 +
1 +
1 +
5 +
4 +
3 +
2 +
1 +
1 +
1 +
1 +
3 +
2 +
1 +
1 +
1 +
3 +
2 +
1 +
1 +
1 +
1 +
2 +
1 +
1 +
2 +
1 +
1 +
1 +
1 +
1 +
...

result: