QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#370840 | #5071. Check Pattern is Good | Graphcity | WA | 40ms | 4080kb | C++20 | 3.1kb | 2024-03-29 17:24:33 | 2024-03-29 17:24:33 |
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];
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],0},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 dfs(int x)
{
vis[x]=1; for(int i=Head[x];i;i=Edge[i].nxt) if(Edge[i].w)
{int y=Edge[i].to; if(!vis[y]) dfs(y);}
}
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-1) For(j,1,m-1) id[i][j]=++s,++s; ++s,t=s+1;
For(i,1,n-1) For(j,1,m-1)
{
if(ch[i][j]!='W' && ch[i][j+1]!='W' && ch[i+1][j]!='W' && ch[i+1][j+1]!='W')
Addedge(id[i][j]+1,t,1),maxf--;
if(ch[i][j]!='B' && ch[i][j+1]!='B' && ch[i+1][j]!='B' && ch[i+1][j+1]!='B')
Addedge(s,id[i][j],1),maxf--;
Addedge(id[i][j],id[i][j]+1,inf);
if(i>1) Addedge(id[i][j],id[i-1][j]+1,inf);
if(j>1) Addedge(id[i][j],id[i][j-1]+1,inf);
if(i>1 && j>1) Addedge(id[i][j],id[i-1][j-1]+1,inf);
}
while(bfs()) dfs(s,inf); printf("%d\n",-maxf);
For(i,1,t) vis[i]=0; dfs(s);
For(i,1,n-1) For(j,1,m-1)
{
if(ch[i][j]!='B' && ch[i][j+1]!='B' && ch[i+1][j]!='B' && ch[i+1][j+1]!='B')
if(vis[id[i][j]]) ch[i][j]=ch[i][j+1]=ch[i+1][j]=ch[i+1][j+1]='W';
if(ch[i][j]!='W' && ch[i][j+1]!='W' && ch[i+1][j]!='W' && ch[i+1][j+1]!='W')
if(!vis[id[i][j]+1]) ch[i][j]=ch[i][j+1]=ch[i+1][j]=ch[i+1][j+1]='B';
}
For(i,1,n) For(j,1,m) if(ch[i][j]=='?') ch[i][j]='W';
// For(i,1,n) printf("%s\n",ch[i]+1); printf("\n");
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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3880kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
1 BW WB 1 BWW WBB WBW 4 BWB WBW BWB
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 40ms
memory: 4080kb
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 BW 12 WBBBWBW BWBBWWW BWBBWWB WBWWBWB BBWBBWB WWBWWWB BWBWWBW WWWWBBW BBWBBWW BWWWWBB 6 BWWBWWB WBBWWWB BWWBBBW BBBWBBB 0 B W W B B W W W B B 15 BWWW WBWW WWWB WBBW BWWB BWBW WBWB BWBW WBWW BWBW 8 WBW WWB WBW BWB WBW WBW BWB BWB 0 W B W B 1 WBWB WWBB 3 B...
result:
wrong answer There are 8 check pattern in you output, but you answered 12 (test case 3)