QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#90517#5250. Combination LocksSolitaryDream#AC ✓22ms3580kbC++202.4kb2023-03-23 14:10:142023-03-23 14:10:18

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-23 14:10:18]
  • 评测
  • 测评结果:AC
  • 用时:22ms
  • 内存:3580kb
  • [2023-03-23 14:10:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
#define DOR(i,s,t) for(int i=(s),_t=(t); i>=_t; --i)
#define EOR(i,x) for(int i=Head[x]; ~i; i=Nxt[i])
const int N=1200,M=N*20;
int Head[N],E[M],Nxt[M],tol;
int cap[M];
void clear() {
    tol=0;
    memset(Head,-1,sizeof(Head));
}
void Edge(int x,int y,int c) {
    E[tol]=y;cap[tol]=c;Nxt[tol]=Head[x];Head[x]=tol++;
    E[tol]=x;cap[tol]=0;Nxt[tol]=Head[y];Head[y]=tol++;
}
int cur[N],dis[N];
int S,T;
bool bfs() {
    static int Q[N],l,r;
    memset(dis,-1,sizeof(dis));

    l=1;r=0;
    dis[S]=0;Q[++r]=S;
    while(l<=r) {
        int x=Q[l++];cur[x]=Head[x];
        EOR(i,x) if(cap[i] && !~dis[E[i]]) {
            dis[E[i]]=dis[x]+1;Q[++r]=E[i];
        }
    }
    return ~dis[T];
}
int dfs(int x,int left) {
    if(x==T || !left) return left;
    int flow=0,t;
    for(int &i=cur[x]; ~i; i=Nxt[i]) {
        if(dis[E[i]]==dis[x]+1 && cap[i]) {
            if(t=dfs(E[i],min(cap[i],left))) {
                cap[i]-=t;cap[i^1]+=t;
                flow+=t;left-=t;
                if(!left) return flow;
            }
        }
    }
    return flow;
}
int dinic() {
    int flow=0;
    while(bfs()) {
        flow+=dfs(S,1e9);
    }
    return flow;
}
int del[N];
int sz[N];
void solve() {
    int n,m;
    cin >> n >> m;
    string A,B;
    cin >> A >> B;
    int st=0;
    FOR(i,0,n-1) {
        if(A[i]==B[i]) st*=2;
        else st=st*2+1;
    }
    FOR(i,0,(1<<n)-1) {
        if(i) sz[i]=sz[i^(i&-i)]+1;
        del[i]=0;
    }
    while(m--) {
        cin >> A;
        cerr << A << endl;
        int v=0;
        FOR(i,0,n-1) {
            if(A[i]=='=') v*=2;
            else v=v*2+1;
        }
        del[v]=1;
    }
    clear();
    S=1<<n,T=S+1;
    FOR(i,0,(1<<n)-1) if(sz[i]%2==0) {
        FOR(j,0,n-1) Edge(i,i^(1<<j),1);
    }
    FOR(i,0,(1<<n)-1) if(sz[i]%2==0 && !del[i] && i!=st) {
        Edge(S,i,1);
    }
    FOR(i,0,(1<<n)-1) if(sz[i]%2==1 && !del[i] && i!=st) {
        Edge(i,T,1);
    }
    dinic();
    // cerr << " -- " << endl;
    if(sz[st]%2==0) Edge(S,st,1);
    else Edge(st,T,1);
    cout << (dinic()?"Alice":"Bob") << '\n';
    // cerr << " -- " << endl;
}
int main() {
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3396kb

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

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: 6ms
memory: 3408kb

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

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

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: 2ms
memory: 3452kb

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: 17ms
memory: 3388kb

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: 22ms
memory: 3572kb

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: 3ms
memory: 3508kb

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: 4ms
memory: 3344kb

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

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

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: 4ms
memory: 3396kb

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: 0ms
memory: 3508kb

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: 1ms
memory: 3476kb

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: 22ms
memory: 3556kb

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: 5ms
memory: 3580kb

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