QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#94004 | #5250. Combination Locks | jaker | AC ✓ | 71ms | 3748kb | C++14 | 2.7kb | 2023-04-04 19:40:20 | 2023-04-04 19:40:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define rept(i,x) for(int i = linkk[x];i;i = e[i].n)
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define se second
#define P pair<int,int>
int rd() {
int x; scanf("%d",&x);
return x;
}
const ll INF = 1e17;
int T,N,C;
int n,m,st;
int ST,ED;
int cnt[1050];
bool vivad[1050];
char s1[20],s2[20];
int linkk[1050] , dep[1050] , t;
struct node{int n,v,y;}e[1010000];
// st : 1<<N end : (1<<N)+1
void insert(int x,int y) {
e[++t].n = linkk[x]; e[t].y = y; e[t].v = 1; linkk[x] = t;
e[++t].n = linkk[y]; e[t].y = x; e[t].v = 0; linkk[y] = t;
}
void build() {
rep(i,0,n-2) {
if( ! (cnt[i] & 1) ) insert( ST , i ); // ou
else insert( i , ED );
rep(j,0,N-1)
if( (cnt[( i ^ (1<<j) )]&1) > (cnt[i]&1) ) insert( i , i ^ (1<<j) );
}
}
void reset() {
rep(i,0,n) vivad[i] = false;
t = 1; rep(i,0,n) linkk[i] = 0 , dep[i] = 0;
}
void init() {
N = rd(); C = rd();
n = (1<<N)+1;
ST = 1<<N; ED = n;
reset();
scanf("%s%s",s1+1,s2+1);
st = 0;
rep(i,1,N) if(s1[i] == s2[i]) st += (1<<(i-1));
rep(i,1,C) {
int res = 0;
scanf("%s",s1+1);
rep(i,1,n) if(s1[i] == '=') res += (1<<(i-1));
vivad[res] = true;
}
build();
}
queue<int>q;
bool bfs() {
rep(i,0,n) dep[i] = -1; dep[ST] = 0;
q.push(ST);
while(!q.empty()) {
int x = q.front(); q.pop();
rept(i,x) {
int y = e[i].y;
if( !vivad[y] && dep[y] == -1 && e[i].v > 0 )
dep[y] = dep[x]+1 , q.push(y);
}
}
return dep[ED] != -1;
}
void output() {
rep(x,0,n) {
printf("#%d\n",x);
rept(i,x) printf("*%d %d\n",e[i].y,e[i].v);
printf("\n");
}
}
ll dfs(int x,ll lazy) {
if(x == ED) return lazy;
if(vivad[x]) return 0;
ll nowlazy = 0 , d = 0;
rept(i,x) {
int y = e[i].y;
if( !vivad[y] && dep[y] == dep[x]+1 && e[i].v > 0 )
if( d = dfs( y , min( 1ll*e[i].v , lazy - nowlazy ) ) ) {
e[i].v -= d;
e[i^1].v += d;
nowlazy += d;
}
}
if(nowlazy == 0) dep[x] = -1;
return nowlazy;
}
void work() {
if(vivad[st]) {
printf("Bob\n");
return;
}
ll ans1 = 0 , ans2 = 0;
while(bfs()) {
ll d;
while(d=dfs(ST,INF)) ans1 += d;
}
t = 1; rep(i,0,n) linkk[i] = 0 , dep[i] = 0;
vivad[st] = true;
build();
while(bfs()) {
ll d;
while(d=dfs(ST,INF)) ans2 += d;
}
if(ans1 != ans2) printf("Alice\n");
else printf("Bob\n");
//printf("**%d\n",st);
//printf("#%d %d\n",ans1,ans2);
}
int main() {
rep(i,0,1024) {
int x = i;
while(x>0) cnt[i] += (x&1) , x >>= 1;
}
T = rd();
while(T--) {
init();
work();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3572kb
input:
2 1 0 0 0 1 1 0 0 .
output:
Alice Bob
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3608kb
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: 3596kb
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: 3604kb
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: 3576kb
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: 4ms
memory: 3604kb
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: 8ms
memory: 3700kb
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: 21ms
memory: 3672kb
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: 3616kb
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: 3676kb
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: 3556kb
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: 3640kb
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: 3552kb
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: 3556kb
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: 3636kb
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: 46ms
memory: 3748kb
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: 71ms
memory: 3692kb
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