QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#411266#5071. Check Pattern is GoodsycqwqWA 5914ms18332kbC++144.3kb2024-05-15 10:51:372024-05-15 10:51:38

Judging History

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

  • [2024-05-15 10:51:38]
  • 评测
  • 测评结果:WA
  • 用时:5914ms
  • 内存:18332kb
  • [2024-05-15 10:51:37]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e6+5,inf=1e9;
struct node
{
    int v,nxt,w;
}e[maxn];
int head[maxn],tot=1;
void add(int x,int y,int w)
{
    e[++tot]=(node){y,head[x],w};
    head[x]=tot;
    e[++tot]=(node){x,head[y],0};
    head[y]=tot;
}
int de[maxn],s,t,n,m,vis[maxn],now[maxn];
int bfs()
{
    int S=s,T=t;
    memset(de,0x3f,sizeof de);
    queue<int> q;
    q.push(S);
    de[S]=0;
    now[S]=head[S];
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        for(int i=head[x];i;i=e[i].nxt)
        {
            int v=e[i].v,w=e[i].w; 
            // cout<<"###"<<x<<' '<<v<<' '<<w<<'\n';
            if(w&&de[v]>de[x]+1)
            {
                de[v]=de[x]+1;
                now[v]=head[v];
                if(v==T)
                    return 1;
                q.push(v);
            }
        }
    }
    return 0;
}
int dfs(int x,int flow)
{
    if(x==t)
        return flow;
    int res=0;
    for(int i=now[x];i;i=e[i].nxt)
    {
        int v=e[i].v,w=e[i].w;
        now[x]=i;
        // cout<<"###"<<x<<' '<<v<<' '<<w<<'\n';
        if(!w||de[v]!=de[x]+1||flow==res)
            continue;
        int tl=dfs(v,min(w,flow-res));
        e[i].w-=tl,e[i^1].w+=tl;
        res+=tl;
    }
    if(!res)
        de[x]=INT_MAX;
    return res;
}
int cnt,id[105][105];
char a[105][105];
int main()
{
    // freopen("matrix.in","r",stdin);
    // freopen("matrix.out","w",stdout);
    ios::sync_with_stdio(0),cin.tie(0); 
    int _;
    cin>>_;
    while(_--)
    {
        memset(head,0,sizeof head);
        tot=1;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            {
                cin>>a[i][j];
                if(a[i][j]=='B')
                    a[i][j]='1';
                if(a[i][j]=='W')
                    a[i][j]='0';
                if((i+j)&1)
                {
                    if(a[i][j]=='1')
                        a[i][j]='0';
                    else if(a[i][j]=='0')
                        a[i][j]='1';
                }

            }
        s=++cnt,t=++cnt;
        
        // for(int i=1;i<=n;i++)
        // {
        //     for(int j=1;j<=m;j++)
        //         cout<<a[i][j];
        //     cout<<'\n';
        // }
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                id[i][j]=++cnt;
        int qwq=0;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            {
                if(a[i][j]=='1')
                    add(s,id[i][j],inf);
                if(a[i][j]=='0')
                    add(id[i][j],t,inf);
                if(a[i][j]=='?')
                {
                    ++qwq;
                    add(s,id[i][j],1);
                    add(id[i][j],t,1);
                }
            }
        // for(int i=1;i<=n;i++)
        // {
        //     for(int j=1;j<=m;j++)
        //         cout<<a[i][j];
        //     cout
        // }
        int ans=0;
        for(int i=1;i<n;i++)
            for(int j=1;j<m;j++)
            {
                ++ans,++ans;
                ++cnt;
                add(s,cnt,1);
                add(cnt,id[i][j],inf);
                add(cnt,id[i+1][j],inf);
                add(cnt,id[i][j+1],inf);
                add(cnt,id[i+1][j+1],inf);
                ++cnt;
                add(cnt,t,1);
                add(id[i][j],cnt,inf);
                add(id[i+1][j],cnt,inf);
                add(id[i][j+1],cnt,inf);
                add(id[i+1][j+1],cnt,inf);
            }
        // cout<<ans<<'\n';
        while(bfs())
            ans-=dfs(s,inf);
        cout<<ans+qwq<<'\n';
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                int tt=id[i][j],pd=0;
                for(int k=head[tt];k;k=e[k].nxt)
                {
                    int v=e[k].v;
                    if(v==t&&e[k].w)
                        pd=1;
                }
                // cout<<i<<' '<<j<<' '<<pd<<'\n';
                if(pd^(i+j&1))
                    cout<<'W';
                else
                    cout<<'B';
                
            }
            cout<<'\n';
        }
    } 
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 13840kb

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: 5914ms
memory: 18332kb

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)