QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370814 | #5071. Check Pattern is Good | Graphcity | WA | 1529ms | 9792kb | C++20 | 2.8kb | 2024-03-29 16:48:21 | 2024-03-29 16:48:22 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=1e6,inf=1e9,lim=1e5;
int n,m,s,t,vis[Maxn+5],dis[Maxn+5],maxf;
char ch[105][105]; int id[105][105],h[105][105],b[105][105];
struct Node{int frm,to,nxt,w;} Edge[Maxn*2+5];
int tot=1,Head[Maxn+5],cur[Maxn+5];
inline void Addedge(int x,int y,int k)
{
Edge[++tot]=Node{x,y,Head[x],k},Head[x]=tot;
Edge[++tot]=Node{y,x,Head[y],0ll},Head[y]=tot;
}
inline int bfs()
{
queue<int> q; For(i,1,t) dis[i]=vis[i]=0,cur[i]=Head[i];
dis[s]=0,vis[s]=1,q.push(s);
while(!q.empty())
{
int x=q.front(); q.pop();
for(int i=Head[x];i;i=Edge[i].nxt)
{
int y=Edge[i].to;
if(Edge[i].w && !vis[y])
dis[y]=dis[x]+1,vis[y]=1,q.push(y);
}
} return vis[t];
}
inline int dfs(int x,int flow)
{
if(!flow || x==t) {maxf+=flow; return flow;}
int used=0,res=0;
for(int i=cur[x];i && used<flow;i=Edge[i].nxt)
{
int y=Edge[i].to; cur[x]=i;
if(dis[y]==dis[x]+1 && Edge[i].w)
if(res=dfs(y,min(flow-used,Edge[i].w)))
used+=res,Edge[i].w-=res,Edge[i^1].w+=res;
} return used;
}
inline void Clear() {For(i,1,t) Head[i]=cur[i]=0; tot=1,maxf=0;}
inline void Solve()
{
cin>>n>>m; s=t=0;
For(i,1,n) scanf("%s",ch[i]+1);
For(i,1,n) For(j,1,m) if(i+j&1)
{
if(ch[i][j]=='W') ch[i][j]='B';
else if(ch[i][j]=='B') ch[i][j]='W';
}
For(i,1,n) For(j,1,m) h[i][j]=++s,b[i][j]=++s;
For(i,1,n-1) For(j,1,m-1) id[i][j]=++s,++s;
++s,t=s+1;
For(i,1,n) For(j,1,m)
{
Addedge(h[i][j],b[i][j],inf);
if(ch[i][j]!='B') Addedge(s,h[i][j],lim);
if(ch[i][j]!='W') Addedge(b[i][j],t,lim);
if(i<n && j<m) Addedge(id[i][j],id[i][j]+1,1);
}
For(i,1,n) For(j,1,m)
{
if(i<n && j<m) Addedge(h[i][j],id[i][j],1),Addedge(id[i][j]+1,b[i][j],1);
if(i>1 && j<m) Addedge(h[i][j],id[i-1][j],1),Addedge(id[i-1][j]+1,b[i][j],1);
if(i<n && j>1) Addedge(h[i][j],id[i][j-1],1),Addedge(id[i][j-1]+1,b[i][j],1);
if(i>1 && j>1) Addedge(h[i][j],id[i-1][j-1],1),Addedge(id[i-1][j-1]+1,b[i][j],1);
}
while(bfs()) dfs(s,inf); printf("%d\n",(n-1)*(m-1)-maxf%lim);
memset(vis,0,sizeof(vis));
for(int i=Head[s];i;i=Edge[i].nxt) if(Edge[i].w) vis[Edge[i].to]=1;
For(i,1,n) For(j,1,m) if(vis[h[i][j]]) ch[i][j]='W'; else ch[i][j]='B';
For(i,1,n) For(j,1,m) if(i+j&1)
{
if(ch[i][j]=='W') ch[i][j]='B';
else if(ch[i][j]=='B') ch[i][j]='W';
}
For(i,1,n) printf("%s\n",ch[i]+1); Clear();
}
int main()
{
// freopen("1.in","r",stdin);
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: 0ms
memory: 9792kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
1 BW WB 1 BWB WBB BBW 4 BWB WBW BWB
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 1529ms
memory: 9772kb
input:
10000 9 2 BB BW WW WW ?W ?B B? W? BB 6 2 ?? ?B B? BW WW ?? 10 7 WBBBW?? ???BWWW ???BWWB ??WWBW? BBWBBWB WWB?WW? BWBW??? WWWWBBW BBWBB?W B?W?W?B 4 7 ??WBWWB ?BBWWWB ?W?BBB? BBBWBBB 10 1 B W ? B B W W W B ? 10 4 ??WW W?W? WWW? ???W ?W?? ?W?W W?W? ?W?W ???W ???W 8 3 WBW W?? ??? ??? W?W W?W ??? ?W? 4 1 ...
output:
3 BB BW WW WW BW WB BW WB BB 2 BW WB BW BW WW WB 9 WBBBWWB WBWBWWW BWBBWWB WBWWBWW BBWBBWB WWBBWWW BWBWBWB WWWWBBW BBWBBWW BBWBWBB 6 BWWBWWB WBBWWWB BWBBBBB BBBWBBB 0 B W B B B W W W B W 15 BWWW WBWB WWWW WBWW BWBW WWWW WWWW WWWW BWBW WBWW 8 WBW WBW BWB WBW WWW WBW BWB WWW 0 W B B W 1 BBBB WBWB 3 BW...
result:
wrong answer There are 3 check pattern in you output, but you answered 6 (test case 4)