QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#411520#5071. Check Pattern is GoodN_z_AC ✓1604ms20492kbC++147.1kb2024-05-15 15:22:402024-05-15 15:22:40

Judging History

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

  • [2024-05-15 15:22:40]
  • 评测
  • 测评结果:AC
  • 用时:1604ms
  • 内存:20492kb
  • [2024-05-15 15:22:40]
  • 提交

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[t]=1;
        queue<int>q;
        q.push(t);
        while(!q.empty())
        {
            int u=q.front();
            if(u==s)return 1;
            q.pop();
            for(auto id:e[u])
            if(flow[id^1]&&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]]+1==dis[s])
            {
                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)*(t+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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9768kb

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: 24ms
memory: 9824kb

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: 27ms
memory: 9960kb

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: 23ms
memory: 9844kb

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: 28ms
memory: 10056kb

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: 28ms
memory: 10216kb

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: 93ms
memory: 9948kb

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: 91ms
memory: 10124kb

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: 10ms
memory: 9916kb

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: 12ms
memory: 12132kb

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: 120ms
memory: 10192kb

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: 123ms
memory: 16236kb

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: 0
Accepted
time: 251ms
memory: 20004kb

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:

4352
WWWWWWBBWWWWBBBWBWWWWBWBWBWWWBWWBWBWWBWWBWBWWWWBWBWBWWBWBBWBBWBWBWWWWBWWBWWBWBWWWBWBBWWBWBWWBWWWBWWB
BBWBWBWWBWBBWBWWWBWWWWBWBWBBBWBBWBWBBWBBWWWWBBBWWWBWBBWWWWBWBWWBWBWBBWBBWBBWBWBWWWBWBWWWBWBBWWWBWBBW
WWBWBWBBWBWBBWBWBWBWWBBWWBWWBBWWBWBWWWWBWBWBWBWBWWWBWWBBWWWWWBWWBWWBWBWWBWWBWBWBWBWWBBWBBBWWW...

result:

ok ok (100 test cases)

Test #14:

score: 0
Accepted
time: 269ms
memory: 16300kb

input:

100
100 100
B?B?W?W??BWWW?BWW??W?W??????BBB?WW??WBBWWBWBWBWW?BB?WB?WBWWWBWWB?W??W?W?BW?WW??W??W??W??W?BW??W?WBB?
W?WW???BBWBWWW?B?WBWWWBW?????W????W?WBWWWWWW??W?WW?W?BWB?W?B?W??BB?BW?BBWWW??BWWW?WW?B???W??W?WWB?WW
????WW??BW?B?BB???WWW?WWBBW?W?WBB?W?W??????B?BWWWWW??WWB?WW???W?BBB??W?BW?W??BW??WWWWW...

output:

3558
BWBBWBWWWBWWWWBWWBWWWWWBWBWBBBBBWWBWWBBWWBWBWBWWBBBBWBBWBWWWBWWBWWBWWBWWBWBWWWBWBWWBWWBWWBBWBWWBWBBW
WBWWBWBBBWBWWWWBBWBWWWBWBWBWBWBWBBWBWBWWWWWWBWWBWWBWBBWBWWWBBWBWBBWBWWBBWWWBWBWWWBWWBBWBBWBWWBWWBWWW
BWBBWWBWBWWBWBBWWBWWWBWWBBWBWBWBBWWWWWBWBWBBWBWWWWWBWWWBWWWBWBWBBBBWBWWBWWWWBBWBBWWWWWBWWBWBW...

result:

ok ok (100 test cases)

Test #15:

score: 0
Accepted
time: 267ms
memory: 12832kb

input:

100
100 100
?BBWBBBB?BBB????BBBWWB???B?BBWBWB?BBBBBBB?W?B?BBB?W?WBBWWBBB?B?B?BB?BB?BBBBBWB?WWBBB?BBBWWB?BB???B?B
B??BBBB????BBBBBWWBBBB??BBW?B?W??BBB?B?BB?BBB??B?B?BWBBWBB?BB?BBBB?BBBBBBWBBWBBBBW?BBBBWBBBWWBBBBBB?
?BBBBWB??B?BB?BB?B?BB?BWB?BBBBBWW?WBBB?BBBWB?B??W??BB?B???BB?B?W?B?BWB?BWWB?WB?WBBB?B?...

output:

2448
WBBWBBBBWBBBWWWWBBBWWBBWWBWBBWBWBWBBBBBBBBWWBWBBBWWWWBBWWBBBWBWBWBBWBBWBBBBBWBWWWBBBWBBBWWBWBBWWWBWB
BWWBBBBWBWBBBBBBWWBBBBWBBBWWBBWBWBBBWBWBBWBBBWBBWBWBWBBWBBWBBWBBBBWBBBBBBWBBWBBBBWWBBBBWBBBWWBBBBBBW
WBBBBWBBWBWBBWBBWBWBBWBWBWBBBBBWWWWBBBWBBBWBWBWBWBWBBWBWBWBBWBWWBBWBWBWBWWBWWBBWBBBWBWWBBBBWB...

result:

ok ok (100 test cases)

Test #16:

score: 0
Accepted
time: 255ms
memory: 17940kb

input:

100
100 100
W??W?BB??WBBBWB?BBW?B???WBB?BW?B???W?BBBWBW?BBB?WWBWWW?BBW?BWB??WBBWB?BWW??BBW?BWBBB?BWBBBBWB??BBB?B
WBW??BWWB?WW?BBBWWBBB?B?WBW??B?BWBW??WWB?BBWWBBB??BB??BB?B?WBB??BBWWBW?B???BWB?WWBB?B?BBBBW??BBBBWW?
???BB?WW?BBBBB??WW??B?B?WB?B?B?BWWB?B?BBWBWWWBBW?BBB?W?B??BB?WBBW?WB?WBBWW?B?BB?WB?WW?...

output:

3208
WWBWBBBBWWBBBWBWBBWWBBWBWBBWBWBBBWBWBBBBWBWBBBBWWWBWWWWBBWBBWBWBWBBWBWBWWBWBBWWBWBBBWBWBBBBWBWWBBBWB
WBWBWBWWBWWWWBBBWWBBBWBWWBWBWBWBWBWBWWWBWBBWWBBBBWBBWBBBWBWWBBBWBBWWBWWBBWBBWBBWWBBWBWBBBBWBWBBBBWWW
BWWBBWWWWBBBBBWBWWWBBWBBWBWBWBWBWWBWBWBBWBWWWBBWWBBBBWWBBWBBWWBBWBWBWWBBWWWBWBBBWBBWWBBWBWBBB...

result:

ok ok (100 test cases)

Test #17:

score: 0
Accepted
time: 266ms
memory: 16192kb

input:

100
100 100
??B????B??W???BB????BW???B??W??????B????B???????????????BB??????WB???BW???W??W?????WB??W???BWB?????W
?W?????BBB?B?W???B?WBBB???????????WBBW?W?B??????W??WBW?????????BWW?BBB????BBB???B???B?W?W????????B?B
B??????B????B????B????WB?BW???????W??W???????W???BB??????????W???W?B??WB??BB???WB??B??...

output:

5779
WBBWBWBBWWWWBWBBBWWBBWWBWBWBWBWBWBWBWBWBBWBWBWBWBBWBWBWBBBWBWWBWWBWWWBWBWBWWWWWBWBWWBWBWBBWBWBWBWWBW
BWWBWBWBBBWBWWWBWBBWBBBWBWBWBWBWBWWBBWBWBBWBWBWBWWBWBWBWBWBWBBWBWWBBBBBWBWBBBWBWBWBWBWWBWWBWBWBWBBWB
BWBWBWBBWBWWBWBWBBWBWBWBWBWBWBWBWBWBWWWBWWBWBWBBWBBBWBWBWBWBWWBWBWWBWBWBWBBBWBWWBBWBWBWBWBWBW...

result:

ok ok (100 test cases)

Test #18:

score: 0
Accepted
time: 282ms
memory: 12440kb

input:

100
100 100
WW??W?BB??BB?BW???BW???W?W?W???B?WBW??BWB?BW????B?W?????W?BWBBWB????BWW??W?WWWBBW?WBW?????BBWBWBWWWB
W????W?WWWW???BBBBWWBBBBWB?WBBWBBW?BBWBWWB???BWWBWW?WW??BWBWWW?W???WB?WWW??BWW??W?W?B?WB?WBWB??B????
BBBB??BBWWB?BB?W???WWWWW??WWWBBBW????W????WB?W??WWB??WW?BWWBB?B?????WWB?BBBW??B?B??WWW...

output:

3677
WWWBWBBBWWBBWBWWWWBWWWWWBWBWWWBBWWBWWBBWBWBWBWBWBWWWBBWBWBBWBBWBWBWBBWWWBWBWWWBBWWWBWBBWWBBBWBWBWWWB
WWBWBWWWWWWWBWBBBBWWBBBBWBWWBBWBBWBBBWBWWBWBWBWWBWWBWWBWBWBWWWBWBWBWBBWWWBWBWWWBWBWWBWWBBWBWBWBBWWBW
BBBBWBBBWWBWBBWWWBWWWWWWBWWWWBBBWBWBWWBWBBWBBWWBWWBWBWWBBWWBBWBBWBWBWWBWBBBWWBBWBWBWWWWBWWBBB...

result:

ok ok (100 test cases)

Test #19:

score: 0
Accepted
time: 267ms
memory: 16532kb

input:

100
100 100
??BB?BB?B?W???BBB?????B?BB?BB?BWBB????W?WBB?W?BB?????????B????B?BB???B?BBBB???B?B?B??BB?BB?W??BB?BBB
BB?BBWB??B?B?BB???BB???BBB??B?BBBB?BB?B??BBB?B???????B??BB??B????BB?B??????BBBBBW?B?B???B????BBB???B
B?BB??B?B??BBB??W????B?BB?BB???BB??BB???BBBB??BB???B?BB??B?BB?BB??B??B??B?B??B??B?B??B...

output:

4003
WWBBWBBWBWWWBWBBBBWWBWBWBBWBBWBWBBBWWBWBWBBWWWBBWBWBWWWBWBWBWWBWBBWBWBWBBBBWWWBWBWBBWBBWBBBWBWBBWBBB
BBWBBWBBWBWBWBBWBWBBWBWBBBBWBWBBBBWBBWBWBBBBWBWWBWBWBBBWBBBWBBWBWBBWBWBWWBWBBBBBWBBWBWWBBBWBWBBBWBWB
BWBBWBBWBWBBBBWBWBWBWBWBBWBBWBWBBBWBBBWBBBBBBWBBWBWBWBBBWBWBBWBBWBBBWBWBBWBWWBBWBWBBWBBWBWBWB...

result:

ok ok (100 test cases)

Test #20:

score: 0
Accepted
time: 267ms
memory: 16304kb

input:

100
100 100
BW?B?B??BB??WWWB?W?B??WBWBB?BWBWB?B?WBBBBBB?B????BBWBBBWWBBB?BBB?WBBBBB?WWBBBWWWB??BBWB?BBWBWWBW?WWB
W??BBWBWBW???W??BWBB?BWBBBWWWBW?BWWWB?B?BBWBWB?B??B?WBBW?W?W?BB?B??WWB?BB?BBBWBB?BBB?WBWWBWBWBWB??BB
BB?WBW??WB?W?BW?WB?B?WB?W?B?B?BW?B??WB?WB?WW???WBBWBWBW?B???W??B??WB??B?BBBWBB?WWW???B...

output:

2489
BWBBWBWBBBWBWWWBWWWBBWWBWBBWBWBWBWBBWBBBBBBWBWBWBBBWBBBWWBBBWBBBWWBBBBBWWWBBBWWWBWWBBWBWBBWBWWBWBWWB
WBWBBWBWBWBWBWBWBWBBWBWBBBWWWBWBBWWWBWBWBBWBWBWBWWBWWBBWBWBWBBBWBWBWWBWBBWBBBWBBWBBBBWBWWBWBWBWBWBBB
BBWWBWWBWBWWWBWBWBWBWWBWWWBWBWBWWBWBWBWWBBWWBWBWBBWBWBWBBBWBWBWBWBWBBWBWBBBWBBWWWWWWWBWBWBWBB...

result:

ok ok (100 test cases)

Test #21:

score: 0
Accepted
time: 261ms
memory: 16236kb

input:

100
100 100
?WBWB?WWWWW??W?????BBW?WW?WWW???WW???BW?WWW???WWW??B?B?W?B?W??WBWW??WWBWBW?WWW?B???WW????WW?W?WW?WWW
WWW??BWW?WW?WW?WW???WWBWB?B?W?BW?W?BWWW?W???WWWW?WBWBBW?W?B?B?WB?B?W?W?BBW??W?W??????W?BWW?W???WWWW?
??WWWW?W?BW????B?W??BWW???W?W??B??WWB?W?WW????W?W?B?W??BBWB??WWBW?WW?W???W??B??WBWWW??...

output:

3481
WWBWBWWWWWWWBWWBBWBBBWWWWBWWWBWBWWWWBBWWWWWBWWWWWBWBWBBWBBWWWBWBWWWBWWBWBWBWWWBBBWBWWBWWBWWBWBWWWWWW
WWWBWBWWBWWBWWBWWBWBWWBWBWBWWWBWBWBBWWWWWWBWWWWWBWBWBBWBWWBWBWWBWBBWBWWBBWWBWBWBWBWBBWBBWWBWBWBWWWWW
BWWWWWBWWBWWBBWBBWBWBWWBWBWBWBWBWBWWBBWBWWWBWBWBWBBBWBWBBWBBWWWBWBWWWWWBWWBWBWBWBWWWWBWBWBWBW...

result:

ok ok (100 test cases)

Test #22:

score: 0
Accepted
time: 96ms
memory: 9956kb

input:

10000
10 10
??????????
?W?W??????
??????B???
???????W??
??????B???
??????????
?????B???W
??????????
??????????
???????W??
10 10
???W?WW???
?WWBB?WWBB
?WB??BBWBW
?W?WW?WW?B
BB???B?W??
?B?BWB??BW
BBWBWB?BB?
??BB?BB???
B?W??W????
?BBBB??BW?
10 10
??B?B??W?W
?BBBBW??B?
BBWWBB?B?B
??W??W??B?
B?W?BB???W
?...

output:

71
WBWBWBWBWB
BWBWBWBWBW
WBWBWBBBWB
BWBWBWWWBW
WBWBWBBBWB
BWBWBWBWBW
WBWBWBWBWW
BWBWBWBWBW
WBWBWBWBWB
BWBWBWBWBW
21
WBBWWWWBWW
BWWBBWWWBB
WWBWWBBWBW
WWBWWWWWWB
BBWBWBWWWB
WBWBWBBWBW
BBWBWBWBBW
WWBBWBBWWB
BBWWBWBWBW
WBBBBBWBWB
45
BWBWBBWWWW
WBBBBWBWBW
BBWWBBWBWB
WBWBWWBWBW
BWWWBBWBWW
WBWWBBBWBB
BWBBW...

result:

ok ok (10000 test cases)

Test #23:

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

input:

10000
10 10
WBWWWWBBWW
WBWWW?BWWW
WWWBBBBWWB
BBBBWBBBWW
WBBBBBWBWW
W?BBBBWWWB
BWBBWBBWBB
BBB?WBWWWB
WBWWBBWWWW
BBWWBBBWBB
10 10
B?WW??W??B
B????WWWBB
?BB?W?WWW?
WWW?W?W??W
W?BB??BBW?
B??BW???BB
WWWWW??BW?
?B?BB???W?
??W???WW??
WBB???W???
10 10
??BW?W?WW?
?BBBBBBBW?
?BBBB?BWW?
B?BBBW???B
BWBBWWW?BB
W...

output:

2
WBWWWWBBWW
WBWWWWBWWW
WWWBBBBWWB
BBBBWBBBWW
WBBBBBWBWW
WBBBBBWWWB
BWBBWBBWBB
BBBBWBWWWB
WBWWBBWWWW
BBWWBBBWBB
29
BBWWWBWBWB
BWBWBWWWBB
WBBBWBWWWB
WWWWWBWWBW
WBBBBWBBWB
BWWBWWBWBB
WWWWWBWBWW
WBWBBWBWWB
BWWBWBWWBW
WBBWBWWBWB
9
BWBWWWWWWW
WBBBBBBBWW
WBBBBWBWWW
BWBBBWBWWB
BWBBWWWBBB
WBWBBWBWBW
BBWWWBW...

result:

ok ok (10000 test cases)

Test #24:

score: 0
Accepted
time: 138ms
memory: 10312kb

input:

1000
100 10
W???W?BBW?
WW??BWWW??
WBB?B?W?W?
W?BB???WWB
?WWB?WW??W
W??W????WB
BW??BBWBB?
BB???W?WBB
???WBW?WW?
?WBB?WBB??
?WB?BB?WBW
W?B?WB?WB?
?BB?WWWWBB
WB??BBWW?W
WB?BW?BWBB
??W?WBWWW?
??W?BBWBB?
WW??WWW?B?
BW??BB??W?
BW??W?W?WW
??BBWW???W
BB??BBWWBW
BBW??BBWWW
??B?WBW?B?
?B?BB?B??W
W??BW?BWBW
WW...

output:

240
WBWBWBBBWB
WWBWBWWWBW
WBBWBBWBWB
WBBBWWBWWB
BWWBWWWBBW
WBBWBWBWWB
BWBWBBWBBW
BBWBWWBWBB
WBWWBWWWWW
BWBBWWBBWB
BWBWBBWWBW
WBBBWBWWBW
WBBBWWWWBB
WBBWBBWWWW
WBWBWWBWBB
BWWBWBWWWB
WBWWBBWBBW
WWBBWWWBBW
BWBWBBBWWB
BWWBWBWBWW
WBBBWWBWBW
BBBWBBWWBW
BBWBWBBWWW
BWBWWBWWBW
WBWBBWBBWW
WWBBWBBWBW
WWWWBWBBBW...

result:

ok ok (1000 test cases)

Test #25:

score: 0
Accepted
time: 145ms
memory: 10456kb

input:

1000
10 100
?????????BBW??????B??WWWW??WW????????WW???W?WBBB????????W?B?W???W?W??W???????B?BW?????B??????B??????
??????B?W??W?W??B?????WBWB?W?????????????WWB????WWW??????W?????????????????W????W?W????W???W?W??B???
BB?B???WWW?W?WBW????????WW???B???B???BB?????WW?????????BB?????B??B??W????B?????B???BW?...

output:

585
WBWBWBWBWBBWWBWBWWBWBWWWWWBWWBWBWBWBWWWBWBWWWBBBWWWBWBWBWBBWWWBWWBWBWWWBWBWBWBWBWWBBWBBBWBWBWBWBWBWB
BWBWBWBWWBWWBWBWBBWBWBWBWBWWBWBWBWBWBWBWBWWBBWBWWWWWBWBWBWWBWBWBBWBWBWBWBWBWBWBWWBWWBWBWBWBWBWBWBWBW
BBWBWBWWWWBWWWBWBWBWBWBWWWBBWBWBWBWBWBBBWBWBWWWBWBWBWBWBBWBWBWBWWBWBWBWBWBWBWBWBBWBBWBWBWBWBWB...

result:

ok ok (1000 test cases)

Test #26:

score: 0
Accepted
time: 374ms
memory: 12864kb

input:

100
100 100
????W?????W?W????B???W???B????????????????????????????????WW????W?W??????W?BB??B??????????WB????W???
?????B??W???????????????B?????????B????????????????????????W??????????????BW??????B?????????????????
???B????????????????B????????????????????B??????B??????W?BB?????????????????B??????W??...

output:

7761
WBWBWWBWBBWBWBWBWBBWBWBWWBBWBWBWBWWWBWBWBWBWBWBWBWBWBWBWWBWWWBWBWBWBWBWBWWWBBWWBWBWBWBWBWBWBWBWBWBWB
BWBWBBWBWWBWBWBWBWWBWBWBBWWBWBWBWBBBWBWBWBWBWBWBWBWBWBWBBWBWBWBWBWBWBWBWBWBWWBBWBWBWBWBWBWBWBWBWBWBW
WBWBWBWBWBWBWBWBWBBWBWBWBWBWBWBWBWBWBWBWBBBWBWBWBWBWBWBWWBBBWBWBWBWBWBWBWBWBBWWBWBWWWBWBWBWBW...

result:

ok ok (100 test cases)

Test #27:

score: 0
Accepted
time: 316ms
memory: 12840kb

input:

100
100 100
BBBW??W??WBWBW?B????B???BWWB?BB??BB?WWBW?W?????BBBWB?BBBB?WBBBW??WWWW????B?W?B??W?W?BB??W??W?BBB??BB
WWB??WW??B?W?WWWWWW?BWW??BW??BBBWWBB?W?W?BBWWWWBWBW??B?WB?B?BBB?W?WWWB???W??W?BB?BWWBW?WW?BW???W??WB
WBBBWW?W?BW????W??B?BBW?B??WW?BB??B?WWW????W?WW??BW??BBW?BBB?BB??WW??W???WWB??WWWW?BB?...

output:

3201
BBBWWBWWBWBWBWWBWWBWBWBWBWWBWBBWBBBWWWBWWWWBWWWBBBWBWBBBBBWBBBWWBWWWWWWBWBWWWBWWWWWWBBWBWBWWWBBBBWBB
WWBWBWWBWBBWBWWWWWWBBWWBWBWWBBBBWWBBWWBWBBBWWWWBWBWWBBWWBWBWBBBBWBWWWBBWBWBWWWBBWBWWBWBWWWBWWBWWWBWB
WBBBWWBWWBWBWBWWBWBWBBWWBWBWWWBBBWBWWWWBWBWWWWWBWBWBWBBWWBBBWBBWBWWWBWWBWWWBWBWWWWBBBBWBWWBWB...

result:

ok ok (100 test cases)

Test #28:

score: 0
Accepted
time: 408ms
memory: 12744kb

input:

100
100 100
?WBWW?W???WWWW?WWWB?BBBBBWWWWBBWWB??B?BB?BWBBWBBBWWWBB?BW?BWBBB??BB???BWBBB?BW?WWBWWWWB??B?BWWWBWBBW
WWW?W?WWWW???BBB??????B?BWBWBB?W??B?W?WWWBWBW?W??WW?B?WBBWW?WWWW??W???BWWB?WWW?W?BBBW??WBBWBW??WW?B?
??BWW?WBBBWBWW?W?WWWW?B???BBBBWBBBBW??W?WWW?BW?BWBWWBBWBBB?BBWBBBB?WBBBBWW?WWWWW??W?WB...

output:

1504
WWBWWWWWWBWWWWWWWWBWBBBBBWWWWBBWWBWWBWBBWBWBBWBBBWWWBBWBWBBWBBBBWBBWBWBWBBBWBWWWWBWWWWBBWBWBWWWBWBBW
WWWBWWWWWWBWBBBBWBWBBWBWBWBWBBBWBWBBWBWWWBWBWBWWBWWWBWWBBWWBWWWWBWWBWBBWWBWWWWWWWBBBWWBWBBWBWBBWWWBW
BWBWWBWBBBWBWWWWBWWWWBBBWBBBBBWBBBBWBWWWWWWWBWBBWBWWBBWBBBWBBWBBBBBWBBBBWWBWWWWWBWWWWBWWWWBBB...

result:

ok ok (100 test cases)

Test #29:

score: 0
Accepted
time: 95ms
memory: 16020kb

input:

100
100 100
WWWWBBBWWBBBW?BBW?BBB?WWBBB?WWBBBWBBBWBBWBWBWWWWWBBWWWBWBBWWBWBW?BBWBBWBW?WWWBBWWWWWWWW?BW?BBWBBW??B
BWWWWBBB?WBBWW?WWB?BBWBB?BBBBBBBWB?WWBWW?WWBBWWWWBBBWBWBWWWBWBWBWWBWWWBBB?B??WBWWWBBBBBBWBBBBW?WB?WB
B?WBWBBBBWWWWBBWWWB?BBWB??WWBWBB?WBBBBBWWBWW?WBBBBBBBWWBWWWWW?BBWBBB?BBB?WBWBB?BBB??BB...

output:

1685
WWWWBBBWWBBBWWBBWWBBBBWWBBBWWWBBBWBBBWBBWBWBWWWWWBBWWWBWBBWWBWBWBBBWBBWBWBWWWBBWWWWWWWWWBWWBBWBBWWBB
BWWWWBBBBWBBWWWWWBWBBWBBWBBBBBBBWBWWWBWWBWWBBWWWWBBBWBWBWWWBWBWBWWBWWWBBBWBWBWBWWWBBBBBBWBBBBWBWBBWB
BWWBWBBBBWWWWBBWWWBWBBWBWBWWBWBBWWBBBBBWWBWWWWBBBBBBBWWBWWWWWWBBWBBBWBBBWWBWBBWBBBWBBBBBBWBWB...

result:

ok ok (100 test cases)

Test #30:

score: 0
Accepted
time: 157ms
memory: 16452kb

input:

100
100 100
BBBWW?BWWW?WB?W?WW?????B?WBWWWBWWWBW?BWW?B???B?WWW??BB???BWB??BBB??WWW?W?W??BBBWBWB?W?BBBB??W??B?WWW
?B?WW????W?WB?W??B???WWW?W?B?WBBBWBWB?W?WWWBW?BBWWBBBW?B?W?WB?WWB?BWWWWW??WBWB?B?WBW??WB?WBWWW???B?B
??BWW?WWBWWB??WB?BW?WWBWWW??W????W???W?WB?BWBB?BWBBB?BW?W?WWWWBWBW?WBWBWBW??BBWWW?WBB?...

output:

2809
BBBWWWBWWWWWBWWBWWWBWBWBWWBWWWBWWWBWWBWWBBBWBBWWWWWWBBWWWBWBWWBBBBWWWWWWBWBWBBBWBWBBWBBBBBWBWBWBWWWW
WBWWWBWBWWBWBWWWBBBWBWWWBWWBBWBBBWBWBWWBWWWBWWBBWWBBBWBBBWBWBBWWBWBWWWWWWBWBWBWBBWBWBWWBWWBWWWBWBBWB
BWBWWBWWBWWBWBWBWBWBWWBWWWBWWBWBWWWBWWBWBWBWBBWBWBBBWBWWWBWWWWBWBWWWBWBWBWBWBBWWWBWBBBWBWWBWW...

result:

ok ok (100 test cases)

Test #31:

score: 0
Accepted
time: 264ms
memory: 14400kb

input:

100
100 100
?BB???B?BBB?WB??B?B??B?BW??BB?BWWW?B?B???WB??B??BB?BBBB?BB????BWB?B??BBBBBBBBBW??BB?BB?B??BBW?B??B?W
?BBB?B?B?BBBBBB?B????B?BB????B??B??BB??BBB?W?BB??BBBBBBB??B??BBB???B?????B?WBB?B??BBBBB?BBBB?BB?B???
BBBW??B??B????BB??BB????B??B??BBBB?BB?B??B???WBB??B?BWB?B?B?B?B?BB?BBB?BWB?????BW???BB...

output:

3817
WBBWBWBWBBBWWBWBBWBWBBWBWBWBBWBWWWWBWBBWWWBBWBWBBBWBBBBWBBWWBWBWBWBWWBBBBBBBBBWWWBBWBBWBWWBBWWBBWBWW
WBBBWBWBWBBBBBBWBWWBWBWBBWBWWBWBBWBBBWWBBBBWBBBWBBBBBBBBWWBBWBBBWBWBBWBWBBWWBBWBBWBBBBBWBBBBWBBWBWBW
BBBWBWBBWBWBWWBBWBBBBWBWBBWBBWBBBBWBBWBWWBWBWWBBWBBWBWBWBWBWBWBWBBWBBBWBWBBWBWBBWBWWBBWWWBBWB...

result:

ok ok (100 test cases)

Test #32:

score: 0
Accepted
time: 496ms
memory: 12668kb

input:

100
100 100
??B?????????WBWB?B??B????????WB?WW????WBW???W??????????B???BWW?????W??W?B?????W???B????WB???B?W?W???
W?BW??W??W???WWB???BWBW?WB??WWWB?B?WB??B???BWW??B??B????????B??BB??B?????B??W?W??W?B???W?????B????BW
??W????B???BB????????????WB????WB???B??BBB????B???WWB?????WW??B????BBW??W?W???BW?W?W??...

output:

5861
BWBWBWBBWBWBWBWBWBWWBWBWBWBWBWBWWWBBWBWBWBBWWBWBWBWWBBWBWBWBWWBWWBWWBWWBBWBWBWWWBWBWBBWWBWBWBWWBWBWB
WBBWWBWWBWBWBWWBBWBBWBWBWBWBWWWBWBWWBWBBBWWBWWBWBWBBWWBWBWBWBBWBBWBBWBBWBBWBWBWBWWWBWWBWWBWBWBBWBWBW
BWWBBWBBWBWBBBWBWBWWBWBWBWBWBWBWBWBWBWBBBBBWBWBBWBWWBBWBWBWWBWBBWBWBBWWBWWWWBWBWBWBWBBWBBWBWB...

result:

ok ok (100 test cases)

Test #33:

score: 0
Accepted
time: 1375ms
memory: 14900kb

input:

100
100 100
?????W???????????????????B????W????W????????????WB??W?????????????W?????????????B??????????W?BW?W???
W?WW????BB????????????????W????????????????????????W????????????????W?W???????????????W????W????????
????????????W??????????WW????????????????????????W??????W???????B?????????B????W??????...

output:

8073
BWBWBWBWWWBWBWBWBWBWBWBWWBBWBWWWBWBWBWBWBWBWBWBWWBWBWBWBWWBWBWBWBWWWBWBWBWBWBWBWBWBWBWBWWBWWWBWBWBWB
WBWWWBWBBBWBWBWBWBWBWBWBBWWBWBWBWBWBWBWBWBWBWBWBBWBWBWBWBBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBBWBWBWBWBWBW
BWBWBWBWBWBWWWBWBWBWBWBWWBBWBWBWBWBWBWBWBWBWBWBWBWWBWBWBWWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWWBWBW...

result:

ok ok (100 test cases)

Test #34:

score: 0
Accepted
time: 1604ms
memory: 20492kb

input:

100
100 100
???B??B????????B?W??????B??????????????B???????????W?????????????????????????W??????????????????????
?????????????????????????????????????B????????????????????????????W??????W???B??????????????????????
??????????????????W????????????????????????????????????????????W??????????????????????...

output:

8988
BWBBBWBWBWBWBWBBBWBWBWBWBWBWBWBWBWBWBWBBBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBW
WBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWWWBWBWBWBWBWBWBWBWBWBWBWBWB
BWBWBWBWBWBWBWBWBWWWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB...

result:

ok ok (100 test cases)