QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#416835 | #5071. Check Pattern is Good | rotcar07 | WA | 74ms | 8168kb | C++14 | 2.5kb | 2024-05-22 09:23:15 | 2024-05-22 09:23:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=20005,maxm=4e5+5;
int fir[maxn],to[maxm],val[maxm],nxt[maxm],tot;inline void addedge(int u,int v,int w){nxt[++tot]=fir[u],to[fir[u]=tot]=v,val[tot]=w;}
inline void add(int u,int v,int w){addedge(u,v,w),addedge(v,u,0);}
int s,t,dep[maxn],num;
bool bfs(){
memset(dep,0,4*num);
queue<int>q;q.push(t);dep[t]=1;
while(!q.empty()){
int p=q.front();q.pop();
if(p==s) return 1;
for(int i=fir[p];i;i=nxt[i])if(!dep[to[i]]&&val[i^1]) dep[to[i]]=dep[p]+1,q.push(to[i]);
}
return 0;
}
int dfs(int p,int res){
if(p==t) return res;
int fl=0;
for(int i=fir[p];i&&res;i=nxt[i]){
if(dep[to[i]]+1==dep[p]&&val[i]){
int z=dfs(to[i],min(res,val[i]));
fl+=z,res-=z,val[i]-=z,val[i^1]+=z;
}
}
if(fl==0) dep[p]=0;
return fl;
}
inline int calc(){int ans=0;while(bfs())ans+=dfs(s,1e9);return ans;}
string S[105];
int id[105][105][2],I[105][105][2];
bool vis[maxn];
void dfs(int p){
if(vis[p]) return;vis[p]=1;
for(int i=fir[p];i;i=nxt[i])if(val[i])dfs(to[i]);
}
inline void solve(){
int n,m;cin>>n>>m;int N=n*m;
tot=1;memset(fir,0,sizeof fir);
memset(id,0,sizeof id);memset(I,0,sizeof I);
for(int i=0;i<n;i++) cin>>S[i];
int tt=0;
auto chk=[&](int x,int y,int k){
if(S[x][y]=='?'||S[x][y]=="BW"[k^((x+y)&1)])return 1;
return 0;
};
for(int k:{0,1})
for(int i=1;i<n;i++)
for(int j=1;j<m;j++)
if(chk(i-1,j-1,k)&&chk(i,j,k)&&chk(i,j-1,k)&&chk(i-1,j,k)) id[i][j][k]=++tt;
s=0,t=tt+1;num=tt+2;
for(int i=1;i<n;i++)
for(int j=1;j<m;j++){
if(id[i][j][0]){
add(s,id[i][j][0],1),I[i][j][0]=tot-1;
for(int x:{i-1,i,i+1})
for(int y:{j-1,j,j+1})
if(id[x][y][1]) add(id[i][j][0],id[x][y][1],1e9);
}
if(id[i][j][1]) add(id[i][j][1],t,1),I[i][j][1]=tot-1;
}
memset(vis,0,sizeof vis);
cout<<tt-calc()<<'\n';dfs(s);
for(int i=1;i<n;i++)
for(int j=1;j<m;j++){
int k=-1;
if(I[i][j][0]&&vis[I[i][j][0]]) k=0;
else if(I[i][j][1]&&!vis[I[i][j][1]]) k=1;
if(~k){
for(int x:{i-1,i})
for(int y:{j-1,j})
S[x][y]="BW"[k^((x+y)&1)];
}
}
for(int i=0;i<n;i++)
for(int j=0;j<m;j++) if(S[i][j]=='?') S[i][j]='B';
for(int i=0;i<n;i++) cout<<S[i]<<'\n';
}
int main(){
int t;cin>>t;
while(t--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 8104kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
1 WB BW 1 BWB WWB BBW 4 BWB WBW BWB
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 74ms
memory: 8168kb
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 BB WB BB 2 BW WB BB BW WW BB 9 WBBBWBB BWBBWWW WBWBWWB BWWWBWB BBWBBWB WWBWWWB BWBWBBW WWWWBBW BBWBBBW BBWBWWB 6 BWWBWWB WBBWWWB BWWBBBW BBBWBBB 0 B W B B B W W W B B 15 BWWW WBWB WWWB BBBW BWWB BWBW WBWB BWBW WBWW BWBW 8 WBW WWB WBW BWB WBW WBW WBW BWB 0 W B B B 1 BBWB WWBB 3 BW...
result:
wrong answer There are 1 check pattern in you output, but you answered 3 (test case 1)