QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#71411 | #5250. Combination Locks | Sorting# | AC ✓ | 9ms | 3512kb | C++ | 2.6kb | 2023-01-09 22:25:36 | 2023-01-09 22:25:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
const int N = 10 + 3;
const int M = (1 << 10) + 3;
int n, c;
int start;
int forb[M];
bool is_forb[M];
bool dfs(int a, int L, vector<vector<int>> &g, vector<int> &btoa, vector<int> &A, vector<int> &B){
if(A[a] != L) return 0;
A[a] = -1;
for(int b: g[a]) if(B[b] == L + 1){
B[b] = 0;
if(btoa[b] == -1 || dfs(btoa[b], L + 1, g, btoa, A, B))
return btoa[b] = a, 1;
}
return 0;
}
int hopcroftKarp(vector<vector<int>> &g, vector<int> &btoa){
int res = 0;
vector<int> A(g.size()), B(btoa.size()), cur, next;
for(;;){
fill(A.begin(), A.end(), 0);
fill(B.begin(), B.end(), 0);
cur.clear();
for(int a: btoa) if(a != -1) A[a] = -1;
rep(a, 0, g.size()) if(A[a] == 0) cur.push_back(a);
for(int lay = 1;; ++lay){
bool islast = 0;
next.clear();
for(int a: cur) for(int b: g[a]){
if(btoa[b] == -1){
B[b] = lay;
islast = 1;
}
else if(btoa[b] != a && !B[b]){
B[b] = lay;
next.push_back(btoa[b]);
}
}
if(islast) break;
if(next.empty()) return res;
for(int a: next) A[a] = lay;
cur.swap(next);
}
rep(a, 0, g.size())
res += dfs(a, 0, g, btoa, A, B);
}
}
void solve(){
cin >> n >> c;
string a, b;
cin >> a >> b;
start = 0;
for(int i = 0; i < n; ++i)
start |= (a[i] == b[i]) << i;
fill(is_forb, is_forb + (1 << n), false);
for(int i = 0; i < c; ++i){
string f;
cin >> f;
forb[i] = 0;
for(int j = 0; j < n; ++j)
forb[i] |= (f[j] == '=') << j;
is_forb[forb[i]] = true;
}
vector<int> num(1 << n);
int cnt[2]{};
for(int i = 0; i < (1 << n); ++i){
int t = __builtin_popcount(i) & 1;
num[i] =cnt[t]++;
}
vector<vector<int>> g(1 << (n - 1));
for(int i = 0; i < (1 << n); ++i){
if(is_forb[i]) continue;
if(__builtin_popcount(i) & 1) continue;
for(int j = 0; j < n; ++j){
int x = i ^ (1 << j);
if(!is_forb[x])
g[num[i]].push_back(num[x]);
}
}
vector<int> btoa(1 << (n - 1), -1);
int before = hopcroftKarp(g, btoa);
for(int i = 0; i < (1 << (n - 1)); ++i)
g[i].clear();
is_forb[start] = true;
for(int i = 0; i < (1 << n); ++i){
if(__builtin_popcount(i) & 1) continue;
if(is_forb[i]) continue;
for(int j = 0; j < n; ++j){
int x = i ^ (1 << j);
if(!is_forb[x])
g[num[i]].push_back(num[x]);
}
}
btoa.clear();
btoa.resize(1 << (n - 1), -1);
int after = hopcroftKarp(g, btoa);
if(after == before)
cout << "Bob\n";
else
cout << "Alice\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3336kb
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: 3508kb
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: 3328kb
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: 0ms
memory: 3508kb
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: 0
Accepted
time: 2ms
memory: 3336kb
input:
20 6 62 188256 588825 ...... .....= ....=. ....== ...=.. ...=.= ...==. ...=== ..=... ..=..= ..=.=. ..=.== ..==.. ..==.= ..===. ..==== .=.... .=...= .=..=. .=..== .=.=.. .=.=.= .=.==. .=.=== .==..= .==.=. .==.== .===.. .===.= .===== =..... =....= =...=. =...== =..=.. =..=.= =..==. =..=== =.=... =.=.....
output:
Bob Bob Alice Alice Alice Bob Bob Bob Bob Alice Bob Bob Alice Alice Alice Bob Alice Alice Alice Alice
result:
ok 20 lines
Test #6:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
20 7 34 1829551 8802318 ....=.= ...=.== ...===. ..=..=. ..=..== ..=.==. .=...== .=..=== .=.=.=. .=.==.. .==.... .==...= .==.=.= .==.=== .===.== =.....= =..=.=. =..=.== =..==.. =..==.= =.=.=.. =.=.=.= =.==..= =.==.=. =.===.. =.===.= =.===== ==..... ==..=== ==.==.= ===.... ===..== ====.== =====.= 7 56...
output:
Alice Bob Bob Alice Bob Bob Alice Bob Alice Bob Alice Alice Alice Bob Bob Alice Bob Bob Alice Bob
result:
ok 20 lines
Test #7:
score: 0
Accepted
time: 3ms
memory: 3428kb
input:
20 8 101 98515990 35971617 ......== ....==.. ....==.= ...=.=.. ...=.=.= ...=.==. ...==... ...==.== ...===.. ...===.= ...====. ..=..=.. ..=..==. ..=.=..= ..=.=.== ..=.==.= ..=.===. ..==...= ..==..== ..==.=.. ..==.=.= ..===..= .=...=.. .=...=.= .=...=== .=..=... .=..=..= .=..==.= .=..===. .=..==== .=....
output:
Alice Alice Bob Alice Alice Alice Alice Bob Bob Bob Bob Bob Bob Alice Bob Alice Bob Bob Alice Bob
result:
ok 20 lines
Test #8:
score: 0
Accepted
time: 4ms
memory: 3464kb
input:
20 9 280 799210637 072013670 ......... ......=.= ......==. .....=... .....=..= .....=.=. .....===. .....==== ....=.... ....=.==. ....==... ....==..= ....==.== ....===== ...=..... ...=....= ...=...== ...=..=.. ...=..=.= ...=..==. ...=.=... ...=.=..= ...=.=.=. ...=.=.== ...=.==.= ...=.==== ...==..=. ....
output:
Alice Bob Bob Alice Bob Bob Alice Alice Bob Bob Bob Bob Alice Bob Bob Alice Alice Bob Alice Bob
result:
ok 20 lines
Test #9:
score: 0
Accepted
time: 2ms
memory: 3332kb
input:
20 3 0 000 000 3 1 000 000 ... 3 1 000 000 =.. 3 2 000 000 ... =.. 3 1 000 000 .=. 3 2 000 000 ... .=. 3 2 000 000 =.. .=. 3 3 000 000 ... =.. .=. 3 1 000 000 ==. 3 2 000 000 ... ==. 3 2 000 000 =.. ==. 3 3 000 000 ... =.. ==. 3 2 000 000 .=. ==. 3 3 000 000 ... .=. ==. 3 3 000 000 =.. .=. ==. 3 4 0...
output:
Alice Bob Alice Alice Alice Alice Alice Alice Bob Bob Alice Bob Alice Bob Alice Alice Alice Alice Alice Alice
result:
ok 20 lines
Test #10:
score: 0
Accepted
time: 0ms
memory: 3328kb
input:
20 3 2 000 000 .=. ..= 3 3 000 000 ... .=. ..= 3 3 000 000 =.. .=. ..= 3 4 000 000 ... =.. .=. ..= 3 2 000 000 ==. ..= 3 3 000 000 ... ==. ..= 3 3 000 000 =.. ==. ..= 3 4 000 000 ... =.. ==. ..= 3 3 000 000 .=. ==. ..= 3 4 000 000 ... .=. ==. ..= 3 4 000 000 =.. .=. ==. ..= 3 5 000 000 ... =.. .=. =...
output:
Alice Alice Alice Alice Alice Bob Alice Alice Alice Alice Alice Alice Bob Bob Alice Bob Alice Bob Alice Alice
result:
ok 20 lines
Test #11:
score: 0
Accepted
time: 3ms
memory: 3336kb
input:
20 3 2 000 000 ==. =.= 3 3 000 000 ... ==. =.= 3 3 000 000 =.. ==. =.= 3 4 000 000 ... =.. ==. =.= 3 3 000 000 .=. ==. =.= 3 4 000 000 ... .=. ==. =.= 3 4 000 000 =.. .=. ==. =.= 3 5 000 000 ... =.. .=. ==. =.= 3 2 000 000 ..= =.= 3 3 000 000 ... ..= =.= 3 3 000 000 =.. ..= =.= 3 4 000 000 ... =.. ....
output:
Bob Bob Bob Bob Bob Bob Alice Bob Alice Bob Alice Alice Alice Alice Alice Alice Bob Bob Alice Bob
result:
ok 20 lines
Test #12:
score: 0
Accepted
time: 1ms
memory: 3328kb
input:
20 3 4 000 000 .=. ==. ..= =.= 3 5 000 000 ... .=. ==. ..= =.= 3 5 000 000 =.. .=. ==. ..= =.= 3 6 000 000 ... =.. .=. ==. ..= =.= 3 1 000 000 .== 3 2 000 000 ... .== 3 2 000 000 =.. .== 3 3 000 000 ... =.. .== 3 2 000 000 .=. .== 3 3 000 000 ... .=. .== 3 3 000 000 =.. .=. .== 3 4 000 000 ... =.. ....
output:
Alice Alice Alice Alice Bob Bob Alice Bob Alice Bob Alice Alice Bob Bob Bob Bob Bob Bob Alice Bob
result:
ok 20 lines
Test #13:
score: 0
Accepted
time: 0ms
memory: 3432kb
input:
20 3 2 000 000 ..= .== 3 3 000 000 ... ..= .== 3 3 000 000 =.. ..= .== 3 4 000 000 ... =.. ..= .== 3 3 000 000 .=. ..= .== 3 4 000 000 ... .=. ..= .== 3 4 000 000 =.. .=. ..= .== 3 5 000 000 ... =.. .=. ..= .== 3 3 000 000 ==. ..= .== 3 4 000 000 ... ==. ..= .== 3 4 000 000 =.. ==. ..= .== 3 5 000 0...
output:
Alice Bob Alice Alice Alice Alice Alice Alice Bob Bob Alice Alice Alice Bob Alice Alice Bob Bob Bob Bob
result:
ok 20 lines
Test #14:
score: 0
Accepted
time: 1ms
memory: 3336kb
input:
20 3 3 000 000 .=. =.= .== 3 4 000 000 ... .=. =.= .== 3 4 000 000 =.. .=. =.= .== 3 5 000 000 ... =.. .=. =.= .== 3 3 000 000 ==. =.= .== 3 4 000 000 ... ==. =.= .== 3 4 000 000 =.. ==. =.= .== 3 5 000 000 ... =.. ==. =.= .== 3 4 000 000 .=. ==. =.= .== 3 5 000 000 ... .=. ==. =.= .== 3 5 000 000 =...
output:
Bob Bob Alice Alice Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Alice Bob Alice Bob Alice Alice
result:
ok 20 lines
Test #15:
score: 0
Accepted
time: 2ms
memory: 3332kb
input:
8 3 4 000 000 ==. ..= =.= .== 3 5 000 000 ... ==. ..= =.= .== 3 5 000 000 =.. ==. ..= =.= .== 3 6 000 000 ... =.. ==. ..= =.= .== 3 5 000 000 .=. ==. ..= =.= .== 3 6 000 000 ... .=. ==. ..= =.= .== 3 6 000 000 =.. .=. ==. ..= =.= .== 3 7 000 000 ... =.. .=. ==. ..= =.= .==
output:
Bob Bob Bob Bob Bob Bob Bob Bob
result:
ok 8 lines
Test #16:
score: 0
Accepted
time: 7ms
memory: 3380kb
input:
20 10 815 4819325421 9470583705 .........= ........=. .......=.. .......=.= .......==. .......=== ......=... ......=..= ......=.=. ......=.== ......==.. ......===. ......==== .....=.... .....=..== .....=.=.. .....==... .....==..= .....==.=. .....==.== .....===.. .....===.= .....====. .....===== .......
output:
Alice Alice Alice Bob Alice Alice Alice Alice Alice Bob Alice Alice Bob Bob Alice Bob Alice Alice Alice Alice
result:
ok 20 lines
Test #17:
score: 0
Accepted
time: 9ms
memory: 3468kb
input:
20 10 7 9410870639 8237933369 .....=.=.= ...==.==.. ..===....= =..==..=.= =..==.=.== =.====.=.= ====.===.= 10 285 0225666838 4493031931 .......... .......=.. .......=== ......==.. ......==.= ......===. .....=.=.. .....=.=== .....==... .....==.== .....===.. ....=...=. ....=..=== ....=.=... ....=.=..=...
output:
Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob Bob
result:
ok 20 lines