QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#102909#5250. Combination LocksLittleEtxTL 255ms3060kbC++231.8kb2023-05-03 20:01:342023-05-03 20:01:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 20:01:37]
  • 评测
  • 测评结果:TL
  • 用时:255ms
  • 内存:3060kb
  • [2023-05-03 20:01:34]
  • 提交

answer

#pragma clang diagnostic push
#pragma ide diagnostic ignored "cert-err34-c"
#include <bitset>
#include <unordered_set>

using namespace std;
typedef bitset<10> GameState;
int n;

void RunCase();
bool IsWin(unordered_set<GameState>& forbidStates, const GameState& current);

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; ++i) {
        RunCase();
    }
}

void RunCase() {
    int c;
    scanf("%d %d", &n, &c);
    char s1[n], s2[n];
    scanf("%s", s1);
    scanf("%s", s2);
    GameState start;
    for (int i = 0; i < n; ++i) {
        if (s1[i] == s2[i]) {
            start.set(i, true);
        }
    }
    unordered_set<GameState> forbidStates;
    for (int i = 0; i < c; ++i) {
        scanf("%s", s1);
        GameState state;
        for (int j = 0; j < n; ++j) {
            if (s1[j] == '=') {
                state.set(j, true);
            }
        }
        forbidStates.insert(state);
    }
    if (IsWin(forbidStates, start)) {
        printf("Alice\n");
    } else {
        printf("Bob\n");
    }
}

bool IsWin(unordered_set<GameState>& forbidStates, const GameState& current) { // NOLINT(misc-no-recursion)
    forbidStates.insert(current);

    //get next state
    GameState nextStates[n];
    for (int i = 0; i < n; ++i) {
        nextStates[i] = current;
        nextStates[i].flip(i);
    }

    for (int i = 0; i < n; ++i) {
        auto next = nextStates[i];
        if (forbidStates.contains(next)) {
            continue;
        }
        // next person loses
        if (!IsWin(forbidStates, next)) {
            forbidStates.erase(current);
            return true;
        }
    }
    // all possible next states are lose or impossible
    forbidStates.erase(current);
    return false;
}

#pragma clang diagnostic pop

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3060kb

input:

2
1 0
0
0
1 1
0
0
.

output:

Alice
Bob

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 3052kb

input:

8
2 0
00
00
2 1
00
00
..
2 1
00
00
=.
2 2
00
00
..
=.
2 1
00
00
.=
2 2
00
00
..
.=
2 2
00
00
=.
.=
2 3
00
00
..
=.
.=

output:

Alice
Alice
Bob
Alice
Bob
Alice
Bob
Bob

result:

ok 8 lines

Test #3:

score: 0
Accepted
time: 2ms
memory: 2884kb

input:

20
4 4
4714
5245
..=.
..==
.==.
==..
4 1
2697
1438
.=..
4 5
9255
0677
...=
..==
=..=
==.=
====
4 12
3292
7326
...=
..=.
..==
.=..
.=.=
.==.
=...
=..=
=.==
==..
==.=
====
4 9
8455
2536
...=
..==
.=..
.=.=
.==.
.===
=...
==..
===.
4 12
5755
1517
...=
..=.
..==
.=..
.=.=
.===
=..=
=.=.
=.==
==..
==.=
=...

output:

Alice
Bob
Alice
Bob
Bob
Alice
Bob
Bob
Alice
Alice
Bob
Alice
Alice
Bob
Bob
Bob
Bob
Bob
Bob
Bob

result:

ok 20 lines

Test #4:

score: 0
Accepted
time: 255ms
memory: 2948kb

input:

20
5 30
99942
90170
.....
....=
...==
..=..
..=.=
..==.
..===
.=...
.=..=
.=.=.
.=.==
.==..
.==.=
.===.
.====
=...=
=..=.
=..==
=.=..
=.=.=
=.==.
=.===
==...
==..=
==.=.
==.==
===..
===.=
====.
=====
5 14
11760
95480
...=.
...==
..=..
..=.=
.=...
.=..=
.====
=....
=...=
=.=..
=.==.
==...
==.==
=====...

output:

Bob
Alice
Alice
Alice
Alice
Bob
Bob
Bob
Alice
Alice
Alice
Bob
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Bob

result:

ok 20 lines

Test #5:

score: -100
Time Limit Exceeded

input:

20
6 62
188256
588825
......
.....=
....=.
....==
...=..
...=.=
...==.
...===
..=...
..=..=
..=.=.
..=.==
..==..
..==.=
..===.
..====
.=....
.=...=
.=..=.
.=..==
.=.=..
.=.=.=
.=.==.
.=.===
.==..=
.==.=.
.==.==
.===..
.===.=
.=====
=.....
=....=
=...=.
=...==
=..=..
=..=.=
=..==.
=..===
=.=...
=.=.....

output:


result: