QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#411462#5071. Check Pattern is GoodN_z_WA 28ms13968kbC++147.1kb2024-05-15 14:24:032024-05-15 14:24:03

Judging History

你现在查看的是最新测评结果

  • [2024-05-15 14:24:03]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:13968kb
  • [2024-05-15 14:24:03]
  • 提交

answer

#if defined(LOCAL) or not defined(LUOGU)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,unroll-loops")
#endif
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#define Setprecision 10
#define between '\n'
#define __int128 long long
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(T x){for(auto &y:x)*this<<y<<between;*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-Setprecision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(T c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(std::string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl

void solve();
main()
{
    int t=1;
    cin>>t;
    while(t--)solve();
}
constexpr int inf=1e9;
struct sber
{
    int to[1000001],dis[100001],arc[1000001];
    vector<int>e[100001];
    int flow[1000001];
	int n,m;
    void clear(){memset(flow,0,sizeof(int)*(m+1));for(int x=0;x<=n;x++)e[x].clear();}
    bool bfs(int s,int t)
    {
        memset(dis,0x3f,sizeof(int)*(n+1));
        dis[s]=1;
        queue<int>q;
        q.push(s);
        while(!q.empty())
        {
            int u=q.front();
            if(u==t)return 1;
            q.pop();
            for(auto id:e[u])
            if(flow[id]&&dis[to[id]]>dis[u]+1)
            {
                dis[to[id]]=dis[u]+1;
                q.push(to[id]);
            }
        }
        return 0;
    }
    int dfs(int s,int t,int up)
    {
        if(s==t)return up;
        int res=0;
        for(int &_=arc[s];_<e[s].size();_++)
        {
            int i=e[s][_];
            if(flow[i]&&dis[to[i]]==dis[s]+1)
            {
                int nw=dfs(to[i],t,min(up,flow[i]));
                flow[i]-=nw,flow[i^1]+=nw;
                up-=nw;
                res+=nw;
                if(up==0)return res;
            }
        }
        return res;
    }
    int dinic(int s,int t)
    {
        int ans=0;
        while(bfs(s,t))
        {
            memset(arc,0,sizeof(int)*(n+1));
            ans+=dfs(s,t,inf);
        }
        return ans;
    }
    void add_edge(int u,int v,int w,int x)
    {
        e[u].emplace_back(2*x);
        e[v].emplace_back(2*x+1);
        to[2*x]=v,to[2*x+1]=u;
        flow[2*x]=w,flow[2*x+1]=0;
    }
};
int a[101][101];
bool vis[100001];
sber u;
void dfs(int nw)
{
    if(!vis[nw])vis[nw]=1;
    else return;
    for(auto id:u.e[nw])
    if(u.flow[id])dfs(u.to[id]);
}
void solve()
{
    int n,m;
    cin>>n>>m;
    int s=0,t=2*n*m+1;
	u.n=t;
    for(int x=1;x<=n;x++)
    for(int y=1;y<=m;y++)
    {
        char ch;
        cin>>ch;
        a[x][y]=ch=='B'?-1:ch=='W'?1:0;
        a[x][y]*=((x^y)&1)?-1:1;
    }
    int id=0,ans=0;
    for(int x=1;x<n;x++)
    for(int y=1;y<m;y++)
    {
        if(a[x][y]!= 1&&a[x][y+1]!= 1&&a[x+1][y]!= 1&&a[x+1][y+1]!= 1)u.add_edge(s,(x-1)*m+y,1,id++),ans++;
        if(a[x][y]!=-1&&a[x][y+1]!=-1&&a[x+1][y]!=-1&&a[x+1][y+1]!=-1)u.add_edge((x-1)*m+y+n*m,t,1,id++),ans++;
        for(int dx=x-1;dx<=x+1;dx++)
        for(int dy=y-1;dy<=y+1;dy++)
        if(1<=dx&&dx<n&&1<=dy&&dy<m)u.add_edge((x-1)*m+y,(dx-1)*m+dy+n*m,inf,id++);
    }
    cout<<ans-u.dinic(s,t)<<endl;
    memset(vis,0,sizeof(int)*(n+1));
    dfs(s);
    for(int x=1;x<n;x++)
    for(int y=1;y<m;y++)
    {
        if(a[x][y]!= 1&&a[x][y+1]!= 1&&a[x+1][y]!= 1&&a[x+1][y+1]!= 1&& vis[(x-1)*m+y    ])a[x][y]=a[x+1][y]=a[x][y+1]=a[x+1][y+1]=-1;
        if(a[x][y]!=-1&&a[x][y+1]!=-1&&a[x+1][y]!=-1&&a[x+1][y+1]!=-1&&!vis[(x-1)*m+y+n*m])a[x][y]=a[x+1][y]=a[x][y+1]=a[x+1][y+1]= 1;
    }
    for(int x=1;x<=n;x++)
    {
        for(int y=1;y<=m;y++)
        a[x][y]*=((x^y)&1)?-1:1,cout<<(a[x][y]==-1?'B':'W');
        cout<<endl;
    }
	u.m=id;
    u.clear();
}
/*
1
3 3
BW?
W?B
?BW
*/

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 13968kb

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
Wrong Answer
time: 28ms
memory: 9912kb

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
WW
9
WBBBWWW
BWBBWWW
WBWBWWB
BWWWBWW
BBWBBWB
WWBWWWB
BWBWWBW
WWWWBBW
BBWBBBW
BWWWWWB
6
BWWBWWB
WBBWWWB
BWWBBBW
BBBWBBB
0
B
W
W
B
B
W
W
W
B
W
15
BWWW
WBWW
WWWB
WBBW
BWWB
BWBW
WBWB
BWBW
WBWW
BWBW
8
WBW
WWB
WBW
BWB
WBW
WWW
WBW
BWW
0
W
B
W
W
1
WBWB
WWBB
3
BW...

result:

wrong answer There are 7 check pattern in you output, but you answered 8 (test case 7)