QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226911#5250. Combination LockshanoAC ✓14ms3904kbC++145.0kb2023-10-26 18:12:472023-10-26 18:12:47

Judging History

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

  • [2023-10-26 18:12:47]
  • 评测
  • 测评结果:AC
  • 用时:14ms
  • 内存:3904kb
  • [2023-10-26 18:12:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pi pair<int,ll>
#define fi first
#define se second
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC target("avx2")

typedef long long T;
const int N = 4e3+5;// beware of bipartite graphs being 2*n
const long long INF = 1e9;
struct edge {
    int a,b;
    T cap, flow ;
};
int n,m,s,t, ptr [N],d[N],q[N];
vector < edge > e;
vector <int > g [N];
void add_edge ( int a, int b, T cap ) {
    edge e1 = {a,b, cap,0LL };
    edge e2 = {b,a,0LL,0LL };
    g[a ]. push_back (( int )e. size () );
    e. push_back ( e1 );
    g[b ]. push_back (( int )e. size () );
    e. push_back ( e2 );
}
bool bfs () {
    int qh =0, qt =0;
    q[ qt ++] = s;
    memset (d, -1,( n +3) * sizeof (d [0]) ) ;
    d[s ] =0;
    while (qh < qt && d [t] == -1) {
        int v = q[ qh ++];
        for ( size_t i = 0; i <g [v ]. size () ; i ++) {
            int id = g[ v ][ i ];
            int to = e [ id ]. b;
            if(d[ to ] == -1 && e [ id ]. flow < e[ id ]. cap) {
                d[ to ] = d [v ]+1;
                q[ qt ++]= to ;
            }
        }
    }
    return d[t ]!= -1;
}
T dfs ( int v,T flow ) {
    if (! flow ) return 0;
    if(v == t) return flow ;
    for (; ptr [v ] <( int )g[v ]. size () ; ptr [v ]++) {
        int id = g[ v ][ ptr [v ]];
        int to = e[ id ]. b;
        if(d[ to ]!= d [v ]+1) continue ;
        T pushed = dfs(to,min(flow,e[ id ].cap-e[ id].flow));
        if( pushed ) {
            e[ id ]. flow += pushed ;
            e[ id ^1]. flow -= pushed ;
            return pushed ;
        }
    }
    return 0;
}
T dinic () {
    T flow =0;
    while (1) {
        if (! bfs () ) break ;
        memset ( ptr,0,( n +3) * sizeof ptr [0]) ;
        while (T pushed = dfs (s, INF )) {
            flow += pushed ;
        }
    }
    return flow ;
}
int nn,c;
int p2[20];
int forbid[3005];
int vs[3005];
/*void build(int msk){
    if(vs[msk])return;
    vs[msk]=true;
    for(int i=0;i<nn;i++){
        int nmsk=(msk^(1<<i));
        if(!forbid[nmsk]){
            add_edge(msk,nmsk,1);
            add_edge(nmsk,msk,1);
            //cout<< msk<<' '<<nmsk<<endl;
            build(nmsk);
        }
    }
}
*/
int main(){
    int tt;cin>>tt;
    p2[0]=1;
    for(int i=1;i<20;i++){
        p2[i]=p2[i-1]*2;
    }
    while(tt--){
        cin>>nn>>c;
        n=p2[nn]+2;
        s=p2[nn]+1,t=s+1;
        string a,b;cin>>a>>b;
        int msk=0;
        for(int i=0;i<nn;i++){
            msk+=(a[i]==b[i]?p2[i]:0);
        }
        for(int i=0;i<c;i++){
            string s;cin>>s;
            int kk=0;
            for(int i=0;i<nn;i++){
                kk+=(s[i]=='='?p2[i]:0);
            }
            forbid[kk]=true;
        }
        //build(msk);
        int bt = __builtin_popcount(msk);
        for(int i=0;i<p2[nn];i++){
            if(__builtin_popcount(i)%2 != bt%2 || forbid[i] || i==msk)continue;
            for(int j=0;j<nn;j++){
                if(!forbid[i^(1<<j)]){
                    add_edge(i,i^(1<<j),1);
                    //add_edge(i^(1<<j),i,1);
                }
            }
        }
        for(int i=0;i<p2[nn];i++){
            if(forbid[i])continue;
            if((__builtin_popcount(i)&1) == (__builtin_popcount(msk)&1)){
                add_edge(s,i,1);
                //cout<<s<<' '<<i<<endl;
            }else{
                add_edge(i,t,1);
                //cout<<i<<' '<<t<<endl;
            }
        }
        int fl1=dinic();
        //memset(vs,0,sizeof vs);
        //forbid[msk]=true;
        for(int i=0;i<p2[nn]+3;i++){
            g[i].clear();
        }
        e.clear();
        memset(ptr,0,sizeof ptr);
        memset(d,0,sizeof d);
        memset(q,0,sizeof q);
        for(int i=0;i<p2[nn];i++){
            if(__builtin_popcount(i)%2 != bt%2 || forbid[i] || i==msk)continue;
            for(int j=0;j<nn;j++){
                if(!forbid[i^(1<<j)]){
                    add_edge(i,i^(1<<j),1);
                    //add_edge(i^(1<<j),i,1);
                }
            }
        }
        for(int i=0;i<nn;i++){
            if(!forbid[msk^(1<<i)]){
                add_edge(msk,msk^(1<<i),1);
                add_edge(msk^(1<<i),msk,1);
            }
        }
        for(int i=0;i<p2[nn];i++){
            if(forbid[i])continue;
            if((__builtin_popcount(i)&1) == (__builtin_popcount(msk)&1)){
                add_edge(s,i,1);
            }else{
                add_edge(i,t,1);
            }
        }
        int fl2=dinic();
        if(fl1==fl2){
            cout<<"Bob"<<endl;
        }else{
            cout<<"Alice"<<endl;
        }
        for(int i=0;i<p2[nn]+3;i++){
            g[i].clear();
        }
        e.clear();
        //memset(vs,0,sizeof vs);
        memset(forbid,0,sizeof forbid);
        memset(ptr,0,sizeof ptr);
        memset(d,0,sizeof d);
        memset(q,0,sizeof q);
        n=s=t=0;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3724kb

input:

2
1 0
0
0
1 1
0
0
.

output:

Alice
Bob

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3636kb

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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: 14ms
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