UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215070#2705. Yet another lights outnaroto20222093ms1140kbC++1.5kb2024-11-25 22:55:052024-11-25 23:12:47

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
const int MN=105;
ll n,m,mp[MN][MN],mpp[MN][MN];
bool op[MN],flag;
char ch;
void write(ll n){if(n<0){putchar('-');write(-n);return;}if(n>9)write(n/10);putchar(n%10+'0');}
ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
char gc(){char ch=getchar();while(ch!='W'&&ch!='B')ch=getchar();return ch;}
void change(ll x, ll y){
    mpp[x][y]^=1;
    for(int i=1; i<=n; i++) mpp[i][y]^=1;
    for(int i=1; i<=m; i++) mpp[x][i]^=1;
}
void work(){
    for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) mpp[i][j]=mp[i][j];
    for(int i=1; i<=n*m; i++){
        ll x=(i+m-1)/m,y=(i%m==0?m:i%m);
        if(op[i]) change(x,y);
    }
    bool ok=true;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++) if(!mpp[i][j]){
            ok=false;
            break;
        }
        if(!ok) break;
    }
    if(ok) flag=true; 
}
void dfs(ll step){
    if(step==n*m+1){
        work();
        return;
    }
    op[step]=0;dfs(step+1);if(flag) return;
    op[step]=1;dfs(step+1);if(flag) return;
}
void solve(){
    n=read();m=read();flag=false;
    for(int i=1; i<=n; i++) for(int j=1; j<=m; j++){ch=gc();mp[i][j]=ch=='W'?1:0;}
    dfs(1);
    if(flag) printf("Yes\n");
    else printf("No\n");
}
int main(){
    ll T=read();while(T--)solve();
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 11ms
memory: 1136kb

input:

10
3 4
BBBB
BWBW
WBBW
3 4
WBWB
WBBB
WBBW
4 4
BWBB
BWWB
WWBB
WBWB
4 3
WBB
BBW
BWB
WBB
4 3
WBB
BWW
WWW...

output:

No
No
Yes
Yes
No
No
Yes
No
No
Yes

result:

ok 10 lines

Test #2:

score: 5
Accepted
time: 36ms
memory: 1140kb

input:

10
4 3
BWB
BWW
WWB
WBW
3 3
BBW
WBW
BBW
3 4
WBWB
BBWB
BBWW
3 3
WBW
BWW
BWW
4 4
WWBB
BWWB
BWWB
BBBW
3 ...

output:

No
No
No
No
Yes
No
No
No
No
Yes

result:

ok 10 lines

Test #3:

score: 5
Accepted
time: 28ms
memory: 1140kb

input:

10
3 3
WBB
BWW
BBW
4 3
WBB
BWW
BBB
WBW
4 4
BWWB
WWWB
WBBB
WBBB
4 4
WBWB
WBBB
WBBB
WBBW
3 3
WBW
BBB
B...

output:

No
No
Yes
Yes
No
No
No
No
Yes
Yes

result:

ok 10 lines

Test #4:

score: 5
Accepted
time: 18ms
memory: 1140kb

input:

10
3 3
BWB
WWW
BBB
4 3
BWW
BWW
BBB
WBW
4 4
BWBW
BWWW
BBWW
WWWW
3 3
BBB
BBB
BWW
4 3
WBB
WBW
BWW
WBB
3...

output:

No
Yes
Yes
No
No
No
No
Yes
No
No

result:

ok 10 lines

Test #5:

score: 0
Time Limit Exceeded

input:

10
15 14
WWWWWWWWBBWBWW
WWBWWBWBWWWWWB
WBWWBBWWBBBBBB
WBBWBWWBWWBWWB
WBBBBBBWBBWWBW
BWBWWWBBWBBWWW
B...

output:


result:


Test #6:

score: 0
Time Limit Exceeded

input:

10
15 15
BBBWBWWWWBWBWWW
BBBBWBWBBBBWWWB
BBBBBBBBBBBBWWB
WBBBWWWBBBBWBBW
BWBBWBWBWWWWWBB
BBWWWWBWBBW...

output:


result:


Test #7:

score: 0
Time Limit Exceeded

input:

10
14 14
WBWBBWWWWBBWBB
BBWWWBBBWBBWWB
BWBWWBBWBWBWBW
BBWBWWBWWWBWWB
WBWWBBBWBWWWBW
WWBWBBBBBWWWBB
W...

output:


result:


Test #8:

score: 0
Time Limit Exceeded

input:

10
15 15
BBBBBBBWWWWBWWW
BBWWWBWWBBWBBWB
BWWBBBBWBBBWWBW
WBWWBBWBWBBWBWW
BWBWWWBBBBWWWWB
WWWBBWWWBWW...

output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

10
15 15
WBBWWWBBWWWWBWW
BWWWWWBBBWBBBBB
BWWWWWBWBWWWBWW
WWWWBBBWWBWBBBB
BWWWWWBWWBWBBWW
WWWWBWBWBBB...

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

10
14 14
WBWWBBBBWWBBWB
BWWWWBBWWBBWBB
BWWBWWWBWWBWBW
BWBBWBBWWBWWWW
BBWBWWWBBBBBBB
WWWWBWBBBBBWBB
W...

output:


result:


Test #11:

score: 0
Time Limit Exceeded

input:

10
99 100
BBBBBWBBBWWWBWBWWBBBWBWWBWWBBWBBWWBWWBWWBBWWWBWBWBWBBBWWBBBWWWWBBBBWWWBWWBWWBWBBWWWWBWWWWW...

output:


result:


Test #12:

score: 0
Time Limit Exceeded

input:

10
99 99
BWWBWBWBBBBWWBWWWBBBBWWBBBBBWBWBBWBWWBBWBBBBWBWBBBWBWBBWWWWBBBWBWWBBBBBBWBBWWBBBBWWBWBWWBWB...

output:


result:


Test #13:

score: 0
Time Limit Exceeded

input:

10
99 99
WBWBBWWWBWWBBWBWBWWBBWBWWBBWBBBWBBBWWWWWBWWBBBBBBWBBBWBBBBBWBBBWWBBWWBBBBBWWBWBBBBBBWBWBBBB...

output:


result:


Test #14:

score: 0
Time Limit Exceeded

input:

10
100 99
BWBWBWWBBWBBBBWWBWBWWBWBBBBBWBBWWBWWBWWWBWBWBBWBWBBBWBBBBWBWBBWWBWWBWWBWBBWWWWWBBBBBWWWBWW...

output:


result:


Test #15:

score: 0
Time Limit Exceeded

input:

10
99 99
WBBBWWBWBBWBWWBWBWWBWWBWBWWWBBBBWWWBBWWWBWBWWWWBBWWWBWBBBBWWBWWWWWBBBWWBBBWBBBBBBWWBWBBWWWW...

output:


result:


Test #16:

score: 0
Time Limit Exceeded

input:

10
100 100
WBBWWBWBWWWWWBBBWBWWWWBWWWBBWWWBBWWWWWBWWBBWBBWWBBWBBWBBBBWWBBWBBWWBWBBWBBWBWWBBWBWWWBBWW...

output:


result:


Test #17:

score: 0
Time Limit Exceeded

input:

10
99 100
WBWWWBWWWWWWBWBBWBWBWWWBWWBBWWBBBWBBBBBBBBBWWBBWWWWWBBWWWBWWWBBWWBWWWWWBBWWWBWWWWBBBWWBWBB...

output:


result:


Test #18:

score: 0
Time Limit Exceeded

input:

10
100 99
BBBWWWBBWBBBBBBWBBWBWWBWBBBWWWBBBWBWBWBBBBWBWWWBBWWBBBWWWBBBWWWBBBBWBWBWBWBWBWWBWWWBWBBBBW...

output:


result:


Test #19:

score: 0
Time Limit Exceeded

input:

10
100 99
BWBBWWWBWWWBBWBWBBWWWBWWWBBWWWBWWBBBWBWBWBBBBWBBBWWBBBWBWWBWWWBWBBBWBBWBBBBBBBBWWWWBBBBWWW...

output:


result:


Test #20:

score: 0
Time Limit Exceeded

input:

10
99 99
WWBWBWBWBWBBBBWBBBBWWWBWWWWBBBBBBBBBWBWWBBWWBBWWWBBWWWBWWWBBWWWWWBWBWWBWWWBWBWBWWWBBWBBBWWB...

output:


result: