QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#297918#7863. Parity Gameucup-team902#WA 0ms3728kbC++173.6kb2024-01-05 13:30:082024-01-05 13:30:09

Judging History

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

  • [2024-01-05 13:30:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3728kb
  • [2024-01-05 13:30:08]
  • 提交

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: 0
Wrong Answer
time: 0ms
memory: 3728kb

input:

4 1
0 1 0 1
1 *
0

output:

Alice
1 +
1 *

result:

wrong answer The interactor wins!