QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#859277 | #9926. Flipping Paths | Itgsurf | RE | 0ms | 0kb | C++14 | 1.0kb | 2025-01-17 17:00:51 | 2025-01-17 17:00:57 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int mod=998244353;
const int N=205,M=405;
int T,n,m;
char s[N][N];
int a[N][N];
char ans[M][M];
int cnt,len[M];
bool check(char c){
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
a[i][j]=s[i][j]!=c;
for(cnt=1;cnt<=401;++cnt){
if(cnt>400) return false;
bool flag=true;
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
if(a[i][j]) flag=false;
if(flag){
--cnt;
break;
}
len[cnt]=0;
int y=1;
for(int i=1;i<=n;++i){
a[i][y]^=1;
int k=0;
for(int j=m;j;--j)
if(a[i][j]){
k=j;
break;
}
while(y<k){
a[i][++y]^=1;
ans[cnt][++len[cnt]]='R';
}
if(i<n) ans[cnt][++len[cnt]]='D';
}
}
puts("YES");
printf("%d\n",cnt);
for(int i=1;i<=cnt;++i)
puts(ans[i]+1);
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
scanf("%s",s[i]+1);
if(!check('B')&&!check('W'))
puts("NO");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
4 3 3 WBB BWB BBW 1 5 WWWWW 2 2 BB BB 4 1 W B B W