QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102909 | #5250. Combination Locks | LittleEtx | TL | 255ms | 3060kb | C++23 | 1.8kb | 2023-05-03 20:01:34 | 2023-05-03 20:01:37 |
Judging History
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
Details
Tip: Click on the bar to expand more detailed information
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 ...... .....= ....=. ....== ...=.. ...=.= ...==. ...=== ..=... ..=..= ..=.=. ..=.== ..==.. ..==.= ..===. ..==== .=.... .=...= .=..=. .=..== .=.=.. .=.=.= .=.==. .=.=== .==..= .==.=. .==.== .===.. .===.= .===== =..... =....= =...=. =...== =..=.. =..=.= =..==. =..=== =.=... =.=.....