QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#102906#5250. Combination LocksLittleEtxML 252ms66500kbC++231.9kb2023-05-03 19:55:542023-05-03 19:55:56

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 19:55:56]
  • 评测
  • 测评结果:ML
  • 用时:252ms
  • 内存:66500kb
  • [2023-05-03 19:55:54]
  • 提交

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

GameState* GetNextStates(const GameState& current) {
    auto* nextStates = new GameState[n];
    for (int i = 0; i < n; ++i) {
        nextStates[i] = current;
        nextStates[i].flip(i);
    }
    return nextStates;
}

bool IsWin(unordered_set<GameState>& forbidStates, const GameState& current) { // NOLINT(misc-no-recursion)
    forbidStates.insert(current);
    auto nextStates = GetNextStates(current);
    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: 2844kb

input:

2
1 0
0
0
1 1
0
0
.

output:

Alice
Bob

result:

ok 2 lines

Test #2:

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

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

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: 252ms
memory: 66500kb

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
Memory Limit Exceeded

input:

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

output:


result: