QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#226880 | #5250. Combination Locks | hano | WA | 1ms | 3752kb | C++14 | 4.2kb | 2023-10-26 17:39:50 | 2023-10-26 17:39:50 |
Judging History
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);
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<nn;i++){
if(forbid[msk^(1<<i)])continue;
if(!vs[msk^(1<<i)])build(msk^(1<<i));
}
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: 1ms
memory: 3728kb
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: 3568kb
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: 3752kb
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: 3636kb
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: -100
Wrong Answer
time: 1ms
memory: 3608kb
input:
20 6 62 188256 588825 ...... .....= ....=. ....== ...=.. ...=.= ...==. ...=== ..=... ..=..= ..=.=. ..=.== ..==.. ..==.= ..===. ..==== .=.... .=...= .=..=. .=..== .=.=.. .=.=.= .=.==. .=.=== .==..= .==.=. .==.== .===.. .===.= .===== =..... =....= =...=. =...== =..=.. =..=.= =..==. =..=== =.=... =.=.....
output:
Bob Bob Alice Alice Alice Bob Bob Bob Bob Alice Bob Bob Alice Alice Bob Bob Alice Alice Alice Alice
result:
wrong answer 15th lines differ - expected: 'Alice', found: 'Bob'