QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#850453 | #9926. Flipping Paths | asdf__ | WA | 0ms | 1584kb | C++14 | 1.5kb | 2025-01-10 08:56:44 | 2025-01-10 08:56:49 |
Judging History
answer
#include<cstdio>
const int N=205;
char a[N][N],b[N][N],ans[2*N][2*N];
int T,n,m,da[N],cnt;
void init(){
for(int i=1;i<m;i++){
while(a[da[i]][i] && da[i]>da[i-1]) da[i]--;
}
}
bool che(){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++) if(a[i][j]!=a[1][1]) return 0;
}
return 1;
}
bool cl(){//0->1
da[0]=1;
cnt=0;
for(int i=1;i<=m;i++) da[i]=n;
init();
while(++cnt<=1){
a[1][1]=1-a[1][1];
for(int i=1,j=0;i<=m;i++){
for(int k=da[i-1]+1;k<=da[i];k++){
a[k][i]=1-a[k][i];
ans[cnt][++j]='D';
}
ans[cnt][++j]='R';
a[da[i]][i+1]=1-a[da[i]][i+1];
}
ans[cnt][n+m-1]=0;
init();
if(da[m-1]==1) break;
}
if(che()) return 1;
cnt++;
a[1][1]=1-a[1][1];
for(int i=2;i<=m;i++){
ans[cnt][i-1]='R';
a[1][i]=1-a[1][i];
}
for(int i=2;i<=n;i++){
ans[cnt][i+m-2]='D';
a[i][m]=1-a[i][m];
}
ans[cnt][n+m-1]=0;
return che();
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%s",a[i]+1);
for(int j=1;j<=m;j++){
if(a[i][j]=='W') a[i][j]=0;
else a[i][j]=1;
b[i][j]=a[i][j];
}
}
if(che()){
printf("YES\n0\n");
continue;
}
if(cl()){
printf("YES\n%d\n",cnt);
for(int i=1;i<=cnt;i++) printf("%s\n",ans[i]+1);
continue;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++) a[i][j]=1-b[i][j];
}
if(cl()){
printf("YES\n%d\n",cnt);
for(int i=1;i<=cnt;i++) printf("%s\n",ans[i]+1);
continue;
}
printf("NO\n");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 1584kb
input:
4 3 3 WBB BWB BBW 1 5 WWWWW 2 2 BB BB 4 1 W B B W
output:
YES 2 DDRR RRDD YES 0 YES 0 NO
result:
ok ok (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 1552kb
input:
323 1 2 BB 1 2 BW 1 2 WB 1 2 WW 2 1 B B 2 1 B W 2 1 W B 2 1 W W 1 3 BBB 1 3 BBW 1 3 BWB 1 3 BWW 1 3 WBB 1 3 WBW 1 3 WWB 1 3 WWW 2 2 BB BB 2 2 BB BW 2 2 BB WB 2 2 BB WW 2 2 BW BB 2 2 BW BW 2 2 BW WB 2 2 BW WW 2 2 WB BB 2 2 WB BW 2 2 WB WB 2 2 WB WW 2 2 WW BB 2 2 WW BW 2 2 WW WB 2 2 WW WW 3 1 B B B 3 ...
output:
YES 0 NO NO YES 0 YES 0 NO NO YES 0 YES 0 NO NO NO NO NO NO YES 0 YES 0 NO YES 1 RD NO YES 1 DR NO YES 2 DR RD NO NO YES 2 DR RD NO YES 1 DR NO YES 1 RD NO YES 0 YES 0 NO NO NO NO NO NO YES 0 YES 0 NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES 0 YES 0 NO NO NO NO NO YES 1 RRD NO NO NO YES 2 RDR RRD ...
result:
wrong answer Jury has answer but participant has not. (test case 75)