QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#89552 | #5250. Combination Locks | molarsu | AC ✓ | 176ms | 3628kb | C++20 | 3.6kb | 2023-03-20 15:56:04 | 2023-03-20 15:56:07 |
Judging History
answer
#include<bits/stdc++.h>
#define ri register int
#define fu(i, a, b) for(ri i = (a), ed = (b); i <= ed; ++i)
#define fd(i, a, b) for(ri i = (a), ed = (b); i >= ed; --i)
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = (1 << 11) + 5;
const int M = N * 10 * 2;
int read(){
int f = 1, x = 0; char ch = getchar();
while(ch > '9' || ch < '0'){ if(ch == '-')f = -1; ch = getchar(); }
while(ch <= '9' && ch >= '0'){ x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
return x * f;
}
int S, T, n, m, tot;
int dis[N], in[N], out[N], L[N], R[N];
int ecnt = 1, head[N], cur[N];
bool vis[N];
struct Edge {
int v, flow, nxt;
}e[M];
void init_edge() {
memset(head, -1, (tot + 2) * sizeof head[0]);
ecnt = 1;
}
int pop_count(int x){
int res = 0;
while(x){
if(x & 1)res++;
x >>= 1;
}
return res;
}
bool cmp(int x, int y){
int res = 0;
if(x == y)return 0;
while(x || y){
if((x & 1 ) != (y & 1))res++;
x >>= 1, y >>= 1;
}
return res == 1;
}
void add_edge(int u, int v, int flow) {
ecnt++;
e[ecnt] = {v, flow, head[u]};
head[u] = ecnt;
//cout << ecnt << " " << u << " " << v << " " << flow << endl;
}
void add2(int u, int v, int flow){
add_edge(u, v, flow);
add_edge(v, u, 0);
}
bool dinic_bfs(int s) {
memset(dis, -1, (tot + 2) * sizeof(dis[0]));
dis[s] = 0;
queue<int> que;
que.push(s);
while (!que.empty()) {
int u = que.front(); que.pop();
for (int i = head[u]; i != -1; i = e[i].nxt) {
int v = e[i].v;
if (dis[v] == -1 && e[i].flow) {
dis[v] = dis[u] + 1;
que.push(v);
}
}
}
//for (int i = 1; i <= n; i++)cout << dis[i] << endl;
return dis[T] != -1;
}
int dinic_dfs(int u, int flow) {
if (u == T) { return flow; }
int delta = flow;
for (int i = cur[u]; i != -1; i = e[i].nxt) {
cur[u] = i;
int v = e[i].v;
if (dis[v] == dis[u] + 1 && e[i].flow) {
int d = dinic_dfs(v, min(delta, e[i].flow));
e[i].flow -= d, e[i ^ 1].flow += d;
delta -= d;
if (delta == 0)break;
}
}
if (delta == flow)dis[u] = -1;
return flow - delta;
}
int dinic() {
int ans = 0;
while (dinic_bfs(S)) {
memcpy(cur, head, (tot + 2) * sizeof head[0]);
ans += dinic_dfs(S, INF);
}
return ans;
}
signed main(){
//n = read(), m = read(), tot = n, S = read(), T = read();
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;cin >> t;
while(t--){
int len, num;
string s1, s2;
memset(vis, 0, (tot + 2) * sizeof vis[0]);
cin >> len >> num;
tot = (1 << len) + 3;
init_edge();
cin >> s1 >> s2;
S = (1 << len) + 1, T = (1 << len) + 2;
int p0 = 0;
fu(i, 0, len - 1) {
p0 <<= 1;
if(s1[i] == s2[i]) p0++;
}
fu(i, 1, num) {
string s;
cin >> s;
int p = 0;
fu(j, 0, len - 1){
p <<= 1;
if(s[j] == '=')p++;
}
vis[p] = 1;
}
fu(i, 0, (1 << len) - 1) {
if(vis[i] || i == p0) continue;
bool f1 = 0;
if(pop_count(i) & 1) f1 = 1, add2(S, i, 1);
else add2(i, T, 1);
fu(j, i + 1, (1 << len) - 1){
if(vis[j] || j == p0) continue;
if(cmp(i, j))
if(f1)add2(i, j, 1);
else add2(j, i, 1);
}
}
int res1 = dinic();
init_edge();
fu(i, 0, (1 << len) - 1) {
if(vis[i]) continue;
bool f1 = 0;
if(pop_count(i) & 1) f1 = 1, add2(S, i, 1);
else add2(i, T, 1);
fu(j, i + 1, (1 << len) - 1){
if(vis[j]) continue;
if(cmp(i, j))
if(f1)add2(i, j, 1);
else add2(j, i, 1);
}
}
int res2 = dinic();
//cout << res1 << " " << res2 << "\n";
if(res2 > res1) cout << "Alice\n";
else cout << "Bob\n";
}
init_edge();
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3352kb
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: 3352kb
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: 3356kb
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: 3492kb
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: 3384kb
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: 1ms
memory: 3500kb
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: 10ms
memory: 3324kb
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: 28ms
memory: 3352kb
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: 3276kb
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: 3404kb
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: 2ms
memory: 3476kb
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: 2ms
memory: 3456kb
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: 1ms
memory: 3280kb
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: 3400kb
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: 3284kb
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: 80ms
memory: 3628kb
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: 176ms
memory: 3552kb
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