QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89186 | #5250. Combination Locks | whatever | AC ✓ | 12ms | 3848kb | C++14 | 2.4kb | 2023-03-19 10:51:34 | 2023-03-19 10:51:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 2e3 + 5;
constexpr int M = 2e4 + 5;
int n, c, msk, ban[N];
string a, b;
struct flow {
int cnt = 1, hd[N], nxt[M << 1], to[M << 1], limit[M << 1];
void clear() {memset(hd, 0, sizeof(hd)), cnt = 1;}
void add(int u, int v, int w) {
nxt[++cnt] = hd[u], hd[u] = cnt, to[cnt] = v, limit[cnt] = w;
nxt[++cnt] = hd[v], hd[v] = cnt, to[cnt] = u, limit[cnt] = 0;
}
int cur[N], dis[N], T;
int dfs(int id, int res) {
if(id == T) return res;
int flow = 0;
for(int i = cur[id]; i && res; i = nxt[i]) {
cur[id] = i;
int c = min(limit[i], res), it = to[i];
if(dis[id] + 1 == dis[it] && c) {
int k = dfs(it, c);
flow += k, res -= k, limit[i] -= k, limit[i ^ 1] += k;
}
}
if(!flow) dis[id] = -1;
return flow;
}
int maxflow(int s, int t) {
int flow = 0;
T = t;
while(1) {
queue<int> q;
memcpy(cur, hd, sizeof(cur));
memset(dis, -1, sizeof(dis));
dis[s] = 0, q.push(s);
while(!q.empty()) {
int t = q.front();
q.pop();
for(int i = hd[t]; i; i = nxt[i])
if(dis[to[i]] == -1 && limit[i])
dis[to[i]] = dis[t] + 1, q.push(to[i]);
}
if(dis[t] == -1) return flow;
flow += dfs(s, N);
}
}
} g;
int calc() {
g.clear();
int S = N - 2, T = N - 1;
for(int i = 0; i < 1 << n; i++) {
if(ban[i]) continue;
if(__builtin_popcount(i) & 1) g.add(i, T, 1);
else {
g.add(S, i, 1);
for(int j = 0; j < n; j++) {
int to = i ^ (1 << j);
if(!ban[to]) g.add(i, to, 1);
}
}
}
return g.maxflow(S, T);
}
void solve() {
cin >> n >> c >> a >> b, msk = 0;
for(int i = 0; i < n; i++) if(a[i] == b[i]) msk |= 1 << i;
memset(ban, 0, sizeof(ban));
while(c--) {
cin >> a;
int S = 0;
for(int i = 0; i < n; i++) if(a[i] == '=') S |= 1 << i;
ban[S] = 1;
}
int c = calc();
ban[msk] = 1;
if(c != calc()) cout << "Alice\n";
else cout << "Bob\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef ALEX_WEI
FILE* IN = freopen("1.in", "r", stdin);
FILE* OUT = freopen("1.out", "w", stdout);
#endif
int T;
cin >> T;
while(T--) solve();
cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
return 0;
}
/*
g++ B.cpp -o B -std=c++14 -O2 -DALEX_WEI
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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: 3768kb
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: 0ms
memory: 3700kb
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: 2ms
memory: 3620kb
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: 3692kb
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: 3ms
memory: 3688kb
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: 1ms
memory: 3772kb
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: 6ms
memory: 3848kb
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: 3652kb
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: 2ms
memory: 3772kb
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: 0ms
memory: 3784kb
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: 0ms
memory: 3684kb
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: 2ms
memory: 3784kb
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: 2ms
memory: 3632kb
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: 3ms
memory: 3632kb
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: 3756kb
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: 12ms
memory: 3832kb
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