QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#411262#5071. Check Pattern is GoodN_z_RE 5647ms12788kbC++147.0kb2024-05-15 10:48:102024-05-15 10:48:10

Judging History

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

  • [2024-05-15 10:48:10]
  • 评测
  • 测评结果:RE
  • 用时:5647ms
  • 内存:12788kb
  • [2024-05-15 10:48:10]
  • 提交

answer

#define LUOGU
#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();
}
long long inf=1e9;
struct sber
{
    int to[100001],dis[100001],arc[100001];
    vector<int>e[100001];
    long long flow[100001];
    sber(){memset(flow,0,sizeof(flow));}
    bool bfs(int s,int t)
    {
        memset(dis,0x3f,sizeof(dis));
        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;
    }
    long long dfs(int s,int t,long long up)
    {
        if(s==t)return up;
        long long res=0;
        for(int &_=arc[s];_<e[s].size();_++)
        {
            int i=e[s][_];
            if(flow[i]&&dis[to[i]]==dis[s]+1)
            {
                long long 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;
    }
    long long dinic(int s,int t)
    {
        long long ans=0;
        while(bfs(s,t))
        {
            memset(arc,0,sizeof(arc));
            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()
{
    u=sber();
    int n,m;
    cin>>n>>m;
    int s=0,t=2*n*m+1;
    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(vis));
    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;
    }
}
/*
1
3 3
BW?
W?B
?BW
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 12516kb

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: 0
Accepted
time: 5305ms
memory: 12404kb

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
BWB
0
W
B
W
W
1
WBWB
WWBB
3
BW...

result:

ok ok (10000 test cases)

Test #3:

score: 0
Accepted
time: 5237ms
memory: 12332kb

input:

10000
9 6
?B?W?W
WWBBWB
?WB?BW
B?W?W?
WW??W?
B???BW
?W?WW?
W?B?B?
?W?BB?
10 1
W
?
?
?
?
?
?
?
B
W
9 4
????
????
W???
?W?B
??WW
?BW?
WW?W
??W?
??W?
3 2
?W
?B
BB
2 7
?W?BWWB
??W???W
9 9
?BW?WWW?W
BW?WBBWWW
W?W????WW
W??WW??WW
W?BWB?B?W
??BB?WWWW
W???WBW?W
WWW???WWW
B?WWWWWW?
8 10
W??BWWW??B
?BWBWBW?BW...

output:

21
WBWWBW
WWBBWB
WWBWBW
BBWBWB
WWBWWB
BBWBBW
BWBWWB
WBBWBW
BWWBBW
0
W
W
W
W
W
W
W
W
B
W
15
WBWB
BWBW
WBWB
BWBB
WBWW
WBWB
WWBW
WBWB
BWWW
1
BW
WB
BB
4
BWBBWWB
WBWWBBW
20
WBWBWWWWW
BWBWBBWWW
WBWBWWBWW
WWBWWBWWW
WBBWBWBWW
BWBBBWWWW
WBWBWBWWW
WWWWBWWWW
BWWWWWWWW
28
WWBBWWWBWB
WBWBWBWWBW
BWBWBWBWBW
WBBWBW...

result:

ok ok (10000 test cases)

Test #4:

score: 0
Accepted
time: 5309ms
memory: 12376kb

input:

10000
7 7
?B??BBW
????BB?
WBBB??B
WW?B???
?B??BBB
BBWB??B
B???BB?
10 6
W?WW??
W??W??
?WWWW?
?WW?WW
WW??W?
W?????
W?WW??
WW???W
WWW??W
?W??W?
2 6
?B??W?
B???BB
1 8
??BWB?W?
5 2
WB
W?
B?
BB
?W
7 5
W????
?WW??
???W?
WWWW?
W?W?W
?W?B?
W?WWB
8 5
B?WBW
B??WW
WWW?B
WBBWB
BW?WW
B?W?B
??WWB
BBW?B
10 4
WWWW
?...

output:

15
WBWBBBW
BWBWBBW
WBBBWWB
WWWBWBW
WBBWBBB
BBWBWWB
BWBWBBW
13
WBWWWB
WWBWBW
WWWWWB
WWWWWW
WWWBWB
WWBWBW
WBWWWB
WWBWBW
WWWBWW
WWBWWW
4
WBWBWW
BWBWBB
0
WWBWBWWW
1
WB
WB
BW
BB
WW
12
WBBWB
BWWBW
WBBWB
WWWWB
WBWBW
BWBBW
WBWWB
7
BBWBW
BWBWW
WWWBB
WBBWB
BWBWW
BWWBB
WBWWB
BBWWB
9
WWWW
WBWB
WWBW
WBWB
BWWB
BW...

result:

ok ok (10000 test cases)

Test #5:

score: 0
Accepted
time: 5271ms
memory: 12400kb

input:

10000
1 1
?
7 9
W?WB????B
?WB??B??W
BBB?W?WB?
WWW??WWW?
WW?B??W?W
?BWW??WWW
B?WW?W?WB
3 7
??BBBB?
BW?WW??
B??B?BW
1 6
?B?WWB
7 1
W
W
W
B
?
W
?
8 8
WW??W?B?
WWW?????
BB??WWWW
?W???WBW
BBW???WB
BWBWBWW?
?W?WW??B
BB?????W
10 8
WWW?W?BW
WB?W?WBW
WW?W?WBW
WWWW?WW?
WBWB?B?W
BW?BW??B
??WWBWWB
W?BW?BWW
W?W?...

output:

0
W
18
WBWBWWBWB
BWBWBBWBW
BBBBWBWBW
WWWWBWWWB
WWBBWBWBW
WBWWBWWWW
BWWWWWWWB
5
WBBBBBW
BWBWWWB
BBWBWBW
0
WBWWWB
0
W
W
W
B
W
W
W
23
WWWBWBBW
WWWWBWWB
BBWBWWWW
WWBWBWBW
BBWBWBWB
BWBWBWWW
WWBWWBWB
BBWBBWBW
19
WWWBWBBW
WBBWBWBW
WWWWWWBW
WWWWBWWB
WBWBWBBW
BWBBWBWB
WBWWBWWB
WWBWBBWW
WBWBWWWW
WWWWBBWB
0
WB...

result:

ok ok (10000 test cases)

Test #6:

score: 0
Accepted
time: 5265ms
memory: 12616kb

input:

10000
9 1
W
B
?
B
W
W
?
W
B
1 10
W??????BWB
5 8
??W??WB?
?B?WWB?W
??????B?
BB??BBBB
WB??BBB?
6 2
?B
??
WB
?B
WW
W?
1 10
WW??BW?BW?
4 3
BW?
???
B?B
??W
10 10
WW?BBW?BW?
WW?BW?????
?WWBW?WB?W
???B?BBBBB
??BBBB?BBW
?WW??W?WBB
W??BB?WBBB
BBWBW?WBBW
?W????BWB?
??BW??WBWB
1 6
??B???
6 5
WBB?W
?WWWW
WWWW?
...

output:

0
W
B
W
B
W
W
W
W
B
0
WWWWWWWBWB
10
BWWBBWBW
WBBWWBWW
BWWBWWBW
BBBWBBBB
WBWBBBBW
2
WB
BW
WB
WB
WW
WW
0
WWWWBWWBWW
6
BWB
WBW
BWB
WBW
26
WWWBBWWBWB
WWWBWWBWBW
BWWBWBWBWW
WBWBWBBBBB
BWBBBBWBBW
BWWWWWBWBB
WBWBBBWBBB
BBWBWBWBBW
BWBWBWBWBW
WBBWWBWBWB
0
WWBWWW
4
WBBWW
BWWWW
WWWWB
WWWBW
WWBBW
WBWWB
0
B
B
B
...

result:

ok ok (10000 test cases)

Test #7:

score: 0
Accepted
time: 5623ms
memory: 12344kb

input:

10000
10 10
?W?WW?W??W
?BWBW?BBWW
?BB?WWW?W?
W?B?WWWWWW
?BWW?WWW?W
BWWWWWWW?W
WBBWW??B??
W??WW?W??W
WWWW?WW?W?
?W?BWW?WW?
10 10
WB?WBBWWWB
?WWWW?WB??
?B?BWW?BW?
WBWBW??W?W
B?WB?WBWWB
WWBWBBWW??
??WBBWBWBW
WWB??WWBWB
B?BWWWWBWW
WW?WWWBWWB
10 10
??W????WW?
?WW?W???W?
??W??WW?W?
WW??WW?WW?
?W??WW?WW?
?...

output:

20
BWBWWBWWBW
WBWBWWBBWW
WBBWWWWWWW
WWBBWWWWWW
WBWWBWWWWW
BWWWWWWWBW
WBBWWWBBWB
WWWWWBWWBW
WWWWBWWBWB
WWWBWWBWWW
24
WBWWBBWWWB
BWWWWBWBBW
WBWBWWBBWB
WBWBWBWWBW
BBWBWWBWWB
WWBWBBWWBW
WBWBBWBWBW
WWBWWWWBWB
BWBWWWWBWW
WWWWWWBWWB
33
WBWWBWBWWW
BWWBWBWBWW
WBWBBWWBWW
WWBWWWBWWW
WWWBWWWWWB
WWWWBWWWBW
BWBBW...

result:

ok ok (10000 test cases)

Test #8:

score: 0
Accepted
time: 5647ms
memory: 12340kb

input:

10000
10 10
?BBBBWBBB?
??W???WB??
BB?W???BB?
?B???BBB??
W??BB?WBBB
?B?B???W?W
?????BB???
?BW???B???
???BBB??BB
BWBBBBBBB?
10 10
BWW?WWB?BW
??B?WBBBWB
B??BB??BWB
BW?BWB???W
?WB?WWW?W?
B??B??W?BB
?WBB?WBB?B
BB??BBWBW?
WB??WBB?BW
?B???B?W??
10 10
??WWWB??BB
?WW???WBWW
???W??W?WW
?W?B?W?W??
WWB?WBB??W
B...

output:

34
WBBBBWBBBW
BWWBWBWBWB
BBBWBWBBBW
WBWBWBBBWB
WWBBBWWBBB
WBWBWBBWBW
BWBWBBBBWB
WBWBWWBWBW
WBWBBBWBBB
BWBBBBBBBW
31
BWWBWWBWBW
WBBWWBBBWB
BWWBBWWBWB
BWWBWBBWBW
WWBWWWWBWB
BBWBWBWWBB
WWBBWWBBWB
BBBWBBWBWB
WBWBWBBWBW
WBBWBBWWWB
33
WBWWWBBWBB
BWWBBWWBWW
WBBWWBWBWW
BWWBBWBWBW
WWBWWBBBWW
BBWBWBWWWW
WWBWB...

result:

ok ok (10000 test cases)

Test #9:

score: 0
Accepted
time: 5105ms
memory: 12456kb

input:

10000
1 100
WWW?BWB?BB?BBW?BWBB?W??B?B?BWWBWB?WWB??BBBBB??BBBBB?BBBWBWWW?B?BBBWW??BBBW???B???W??W??BW?B?B?W??WB?
1 100
?WBW?WB?BBBB?BWBWB???WWB?BBB?BBW?B?B??W?B??BBW??WBBW???WW?BBBB?WWB?WBB???WBBB?BBW?W??BW?B??BBBBBBBWB
1 100
W?????BBB?BB?BB?????BWWWB?B???BB??????B??BWW???B??B?B???????BBB??B?BBB???B...

output:

0
WWWWBWBWBBWBBWWBWBBWWWWBWBWBWWBWBWWWBWWBBBBBWWBBBBBWBBBWBWWWWBWBBBWWWWBBBWWWWBWWWWWWWWWBWWBWBWWWWWBW
0
WWBWWWBWBBBBWBWBWBWWWWWBWBBBWBBWWBWBWWWWBWWBBWWWWBBWWWWWWWBBBBWWWBWWBBWWWWBBBWBBWWWWWBWWBWWBBBBBBBWB
0
WWWWWWBBBWBBWBBWWWWWBWWWBWBWWWBBWWWWWWBWWBWWWWWBWWBWBWWWWWWWBBBWWBWBBBWWWBBWWWWWWWWWWWWWWBWW...

result:

ok ok (10000 test cases)

Test #10:

score: 0
Accepted
time: 5067ms
memory: 12364kb

input:

10000
100 1
W
B
B
?
B
B
B
?
B
B
B
B
W
B
B
B
?
?
B
?
B
B
?
W
B
W
?
B
?
B
W
W
?
W
?
B
?
B
B
?
W
W
B
?
B
B
?
?
W
W
B
B
?
B
B
?
B
?
?
?
W
B
W
B
?
B
W
?
?
B
B
B
B
?
B
?
W
B
B
W
B
?
W
B
B
?
B
B
?
B
?
W
?
B
?
B
B
?
B
W
100 1
?
W
?
W
?
W
W
W
W
W
B
W
?
?
B
B
?
W
?
B
W
W
W
W
?
?
?
?
W
W
B
W
W
W
W
W
?
W
W
W
?
...

output:

0
W
B
B
W
B
B
B
W
B
B
B
B
W
B
B
B
W
W
B
W
B
B
W
W
B
W
W
B
W
B
W
W
W
W
W
B
W
B
B
W
W
W
B
W
B
B
W
W
W
W
B
B
W
B
B
W
B
W
W
W
W
B
W
B
W
B
W
W
W
B
B
B
B
W
B
W
W
B
B
W
B
W
W
B
B
W
B
B
W
B
W
W
W
B
W
B
B
W
B
W
0
W
W
W
W
W
W
W
W
W
W
B
W
W
W
B
B
W
W
W
B
W
W
W
W
W
W
W
W
W
W
B
W
W
W
W
W
W
W
W
W
W
W
B
W
W
B
W
B
...

result:

ok ok (10000 test cases)

Test #11:

score: 0
Accepted
time: 916ms
memory: 12788kb

input:

1000
100 10
WWWB?WWW?W
W????????W
WB?W??WW?W
WBB?WWW??B
?WWWW?WW?W
?WWWW?W?WB
?B??W?W???
WW?W?BWWW?
WW?B?W?W?W
????WW??W?
BWB??WWWW?
W??W??WW??
W?WBB??WWW
?WWBBWW?WW
?WBWW?B???
???WWW???W
??WW?WWW??
????W?BW?W
???W?W?W?W
?WW?WW?WB?
BW??WW?WW?
WB?WWWWW?W
??BWW??W?W
W??B?WWWW?
WWW?W??WWW
BBBW??W?W?
??...

output:

335
WWWBWWWWBW
WWBWBWBBWW
WBWWWBWWBW
WBBWWWWBWB
BWWWWWWWBW
BWWWWWWBWB
WBWBWWWWBW
WWBWBBWWWB
WWWBWWBWBW
WBWBWWWBWB
BWBWBWWWWB
WWBWWBWWBW
WBWBBWBWWW
BWWBBWWBWW
BWBWWBBWWB
WBWWWWWBBW
BWWWBWWWWB
WBWBWBBWBW
BWBWBWWWWW
WWWBWWWWBW
BWBWWWWWWB
WBWWWWWWBW
BWBWWBWWBW
WBWBBWWWWB
WWWBWBBWWW
BBBWBWWBWB
WBWBWWBWBW...

result:

ok ok (1000 test cases)

Test #12:

score: 0
Accepted
time: 915ms
memory: 12636kb

input:

1000
10 100
BBWB??W??B?BWB?BBB??WWWW?B???WBB??WW???WWBW?B??W??BW?BWBBBW?BWBW?WBW?B?WWB??B?B?BBWWWBBBBW?BB???B?WB
??????WWWBWBBB??W??WW??BWBW??W??????WWWB?B??B?????W?B?????W??BBBBWBW??BWWWB???WBWB?BB?WW?B????W?WWB?
WB?BBBW?B??BB?WWW?B??WBB??W?BBW??BB??BB???BB??B??WB??W?B?B?WWWWW?BB??W?W?WBB??B?WWBBB?...

output:

330
BBWBWBWWWBWBWBWBBBWBWWWWBBBWBWBBWBWWBWBWWBWBBWBWBWBWWBWBBBWWBWBWWWBWWBWWWBWBBWBWBBWWWBBBBWWBBWBWBBWB
BWBWBWWWWBWBBBBWWWBWWBWBWBWBWWBWBWBBWWWBWBBWBBWBWBWBBWBWBWWBWBBBBWBWBWBWWWBWWBWBWBWBBWWWWBBWBBWBWWBW
WBWBBBWWBWBBBWWWWBBWBWBBBWWWBBWBWBBBWBBWBWBBWWBWBWBWBWWBWBBWWWWWWBBBWWWWWWBBBWBBWWBBBWBWWBWBWW...

result:

ok ok (1000 test cases)

Test #13:

score: -100
Runtime Error

input:

100
100 100
?WW?WW??WWW??BBW??WW??W???W?W?W?????W?W?BWBW??WBW????W??BB??BW?W??W????WBW?????WWB??BWW????W??W??WW?
B?????WW???B?BWWWB?WWW?WB?BB??????W??W?BWWW?BB??WWBWB?WWW????WW?W??BB?BBWB?W????W???BWWW??BBWWW???BW
W?BW??????WBB?B????W?BBW????BBW????W?W?????B?B??WW??????WWWWW?W??WW?WBW??W??W????BWWB?...

output:


result: