QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#296326 | #5071. Check Pattern is Good | zjy0001 | RE | 1ms | 4028kb | C++14 | 4.2kb | 2024-01-02 19:20:36 | 2024-01-02 19:20:36 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
char wS[262144],rdc[262144],*rS,*rT,*wT=wS;
#define gc() (rS==rT?rT=rdc+fread(rS=rdc,1,262144,stdin),rS==rT?EOF:*rS++:*rS++)
#define flush() fwrite(wS,1,wT-wS,stdout),wT=wS
inline void pc(const char&x){*wT++=x;if(__builtin_expect(wS+262144==wT,0))flush();}
template<class T=int>inline T read(){
T x(0);char c;bool f(1);while(!isdigit(c=gc()))if(c==45)f=!f;
if(f)do x=x*10+(c&15);while(isdigit(c=gc()));
else do x=x*10-(c&15);while(isdigit(c=gc()));
return x;
}
template<>inline void read(){while(gc()<33);while(gc()>32);}
template<>inline char read(){char c;while((c=gc())<33);return c;}
template<>inline string read(){char c;string s;while((c=gc())<33);do s+=c;while((c=gc())>32);return s;}
inline int read(char*const s){char c,*t=s;while((c=gc())<33);do *t++=c;while((c=gc())>32);return *t=0,t-s;}
template<class T>inline void write(T x){
int o=0;char _[50];
if(x>=0)do _[o++]=(x%10)|48;while(x/=10);
else{pc(45);do _[o++]=-(x%10)|48;while(x/=10);}
for(;o;pc(_[--o]));
}
template<>inline void write(char x){pc(x);}
template<>inline void write(char*s){for(;*s;pc(*s++));}
template<>inline void write(const char*s){for(;*s;pc(*s++));}
template<class T>inline void write(const basic_string<T>&x){for(auto c:x)write(c);}
template<class T>inline void write(const initializer_list<T>&x){for(auto c:x)write(c),pc(32);}
template<class T,class...U>inline void write(const T&x,const U&...y){write(x),write(y...);}
const int N=2e4+5,INF=1e7;
int n,m,s=0,t=1,iT;
char a[105][105];
int id[105][105][2];
struct edge{int v,w,nxt;};
vector<edge>G[N];
int em,h[N],d[N],gap[N],vs[N];
inline void add(const int&u,const int&v,const int&w){
const int pu=G[u].size(),pv=G[v].size();
G[u].push_back(edge{v,w,pv});
G[v].push_back(edge{u,0,pu});
}
inline void clear(const int&__n){
for(int i=0;i<__n;++i)vector<edge>().swap(G[i]),d[i]=N-2,gap[i]=0;
}
inline void bfs(){
int ql=0,qr=1;
static int Q[N];
for(d[Q[1]=t]=0;ql<qr;){
int u=Q[++ql];
for(auto [v,w,_]:G[u])if(d[v]==N-2)++gap[d[Q[++qr]=v]=d[u]+1];
}
}
inline int dfs(const int&u,int mf){
if(u==t)return mf;
int res=0;
for(int&i=h[u];i<G[u].size();++i){
auto [v,w,j]=G[u][i];
if(d[v]+1==d[u]&&w){
int dd=dfs(v,min(mf,w));
G[u][i].w-=dd,mf-=dd,G[v][j].w+=dd,res+=dd;
if(!mf)return res;
}
}
if(!--gap[d[u]])d[s]=N-2;
++gap[++d[u]];
return res;
}
inline int isap(const int&__n){
int ans=0;
for(bfs();d[s]<=__n;ans+=dfs(s,INF))memset(h,0,__n<<2);
return ans;
}
inline void dfs_(const int&u,const int&c){
vs[u]=c;
for(auto [v,w,_]:G[u])if(w&&vs[v]!=c)dfs_(v,c);
}
inline void MAIN(){
n=read(),m=read(),clear((n-1)*(m-1)*2+2);
for(int i=1;i<=n;++i){
read(a[i]+1);
for(int j=1;j<=m;++j)
if(((i^j)&1)&&isalpha(a[i][j]))a[i][j]^='B'^'W';
}
int cnt=1;
for(int i=1;i<n;++i)
for(int j=1;j<m;++j){
if(a[i][j]!='W'&&a[i+1][j]!='W'&&a[i][j+1]!='W'&&a[i+1][j+1]!='W')add(s,id[i][j][0]=++cnt,1);
if(a[i][j]!='B'&&a[i+1][j]!='B'&&a[i][j+1]!='B'&&a[i+1][j+1]!='B')add(id[i][j][1]=++cnt,t,1);
}
for(int i=1;i<n;++i)
for(int j=1;j<m;++j)if(id[i][j][0])
for(int _i=max(1,i-1);_i<=min(n-1,i+1);++_i)
for(int _j=max(1,j-1);_j<=min(m-1,j+1);++_j)
if(id[_i][_j][1])add(id[i][j][0],id[_i][_j][1],INF);
write(cnt-1-isap(cnt),'\n'),dfs_(s,++iT);
for(int i=1;i<n;++i)
for(int j=1;j<m;++j)
if(id[i][j][0]&&vs[id[i][j][0]]==iT)
a[i][j]=a[i+1][j]=a[i][j+1]=a[i+1][j+1]='B';
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
if(!isalpha(a[i][j]))a[i][j]='W';
if((i^j)&1)a[i][j]^='B'^'W';
}
write(a[i]+1,'\n');
}
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
#define LOCAL
#ifndef LOCAL
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
for(int T=read();T--;MAIN());
return flush(),0;
}
/*
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4028kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
1 WB BW 1 BWW WWB WBW 4 BWB WBW BWB
result:
ok ok (3 test cases)
Test #2:
score: -100
Runtime Error
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 ...