QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#847853 | #9926. Flipping Paths | J_R_X | WA | 17ms | 4444kb | C++14 | 4.9kb | 2025-01-08 12:02:11 | 2025-01-08 12:02:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m;
int c[205][205];
int f[205][205][2];
char rd[205][205];
vector<vector<char> > ans;
vector<char> S;
void pt(int x,int y) {
if(x==n&&y==m) {
ans.push_back(S);
// for(auto c:S) cout<<c; cout<<'\n';
return ;
}
// cout<<f[x][y][0]<<'\n';
// cout<<x<<' '<<y<<' '<<f[x][y][0]<<' '<<f[x][y][1]<<'\n';
if(f[x][y][0]) {
f[x][y][0]--;
S.push_back('D');
pt(x+1,y);
S.pop_back();
}else if(f[x][y][1]) {
f[x][y][1]--;
S.push_back('R');
pt(x,y+1);
S.pop_back();
}else {
cout<<"?????\n";
}
return ;
}
int tot, t;
void solve() {
ans.clear();
cin>>n>>m;
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
char ch;
cin>>ch;
c[i][j]=ch=='B';
rd[i][j]=ch;
}
}
int D=c[1][1];
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
c[i][j]^= D;
}
}
if(n>=2&&m>=2&&(c[1][2]^c[2][1])!=c[1][1]) {
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
c[i][j]^=1;
}
}
}
memset(f,0,sizeof(f));
vector<int> vec;
vec.push_back(c[1][1]);
for(int s=3;s<=n+m;s++) {
vector<int> vec2;
for(int i=max(1,s-m);i<=min(s-1,n);i++) vec2.push_back(c[i][s-i]);
int bg=max(0,s-m-2);
if(vec.size()<vec2.size()) {
for(int i=0;i<vec.size();i++) {
if(!i) f[bg+i+1][s-i-bg-2][1]=vec2[i];
else f[bg+i+1][s-i-bg-2][1]=vec2[i]^f[bg+i][s-i-bg-1][0];
f[bg+i+1][s-i-bg-2][0]=vec[i]^f[bg+i+1][s-i-bg-2][1];
if(i==vec.size()-1&&f[bg+i+1][s-i-bg-2][0]!=vec2[i+1]) {
cout<<"NO\n";
return ;
}
}
}else if(vec.size()>vec2.size()) {
f[bg+1][s-bg-2][0]=vec[0];
for(int i=1;i<vec.size();i++) {
f[bg+i+1][s-i-bg-2][1]=vec2[i-1]^f[bg+i][s-i-bg-1][0];
f[bg+i+1][s-i-bg-2][0]=vec[i]^f[bg+i+1][s-i-bg-2][1];
if(i==vec.size()-1&&f[bg+i+1][s-i-bg-2][0]!=0) {
cout<<"NO\n";
return ;
}
}
}else {
if(n>=m) {
f[bg+1][s-bg-2][0]=vec[0];
if(0==vec.size()-1&&f[bg+1][s-bg-2][0]!=vec2[0]) {
cout<<"NO\n";
return ;
}
for(int i=1;i<vec.size();i++) {
f[bg+i+1][s-i-bg-2][1]=vec2[i-1]^f[bg+i][s-i-bg-1][0];
f[bg+i+1][s-i-bg-2][0]=vec[i]^f[bg+i+1][s-i-bg-2][1];
if(i==vec.size()-1&&f[bg+i+1][s-i-bg-2][0]!=vec2[i]) {
cout<<"NO\n";
return ;
}
}
}else {
for(int i=0;i<vec.size();i++) {
if(!i) f[bg+i+1][s-i-bg-2][1]=vec2[i];
else f[bg+i+1][s-i-bg-2][1]=vec2[i]^f[bg+i][s-i-bg-1][0];
f[bg+i+1][s-i-bg-2][0]=vec[i]^f[bg+i+1][s-i-bg-2][1];
if(i==vec.size()-1&&f[bg+i+1][s-i-bg-2][0]!=0) {
cout<<"NO\n";
return ;
}
}
}
}
swap(vec,vec2);
}
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
if(i+j==2||i+j==n+m) continue;
int sum=f[i-1][j][0]+f[i][j-1][1];
while(f[i][j][0]+f[i][j][1]>sum) {
if((i!=n)&&(j==m||f[i][j][0]>f[i][j][1])) f[i][j][0]-=2;
else f[i][j][1]-=2;
}
while(f[i][j][0]+f[i][j][1]<sum) {
if((i!=n)&&(j==m||f[i][j][0]<f[i][j][1])) f[i][j][0]+= 2;
else f[i][j][1]+= 2;
}
}
}
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
if(f[i][j][0]<0) {
int c=(-f[i][j][0]+1)/2*2;
for(int k=1;k<j;k++) f[1][k][1]+= c;
for(int k=1;k<n;k++) f[k][j][0]+= c;
for(int k=j;k<m;k++) f[n][k][1]+= c;
}
if(f[i][j][1]<0) {
int c=(-f[i][j][1]+1)/2*2;
for(int k=1;k<i;k++) f[k][1][0]+= c;
for(int k=1;k<m;k++) f[i][k][1]+= c;
for(int k=i;k<n;k++) f[k][m][0]+= c;
}
}
}
cout<<"YES\n";
while(f[1][1][0]||f[1][1][1]) pt(1,1);
cout<<ans.size()<<'\n';
for(auto S:ans) {
for(auto c:S) cout<<c; cout<<'\n';
}
return ;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>t;
while(t--) tot++, solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3936kb
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: 0
Accepted
time: 2ms
memory: 4136kb
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:
ok ok (323 test cases)
Test #3:
score: 0
Accepted
time: 2ms
memory: 3944kb
input:
278 2 4 BWBW WWBB 2 4 BWBW WWBW 2 4 BWBW WWWB 2 4 BWBW WWWW 2 4 BWWB BBBB 2 4 BWWB BBBW 2 4 BWWB BBWB 2 4 BWWB BBWW 2 4 BWWB BWBB 2 4 BWWB BWBW 2 4 BWWB BWWB 2 4 BWWB BWWW 2 4 BWWB WBBB 2 4 BWWB WBBW 2 4 BWWB WBWB 2 4 BWWB WBWW 2 4 BWWB WWBB 2 4 BWWB WWBW 2 4 BWWB WWWB 2 4 BWWB WWWW 2 4 BWWW BBBB 2 ...
output:
NO NO NO NO NO NO YES 3 DRRR RRDR RRRD NO NO NO NO NO NO NO NO NO YES 2 DRRR RRDR NO NO NO YES 1 DRRR NO NO NO NO NO NO NO NO NO NO NO NO NO YES 2 DRRR RRRD NO NO YES 2 DRRR RRRD NO NO NO NO NO NO NO NO NO NO NO NO NO YES 1 DRRR NO NO NO YES 2 DRRR RRDR NO NO NO NO NO NO NO NO NO YES 3 DRRR RRDR RRR...
result:
ok ok (278 test cases)
Test #4:
score: 0
Accepted
time: 2ms
memory: 4136kb
input:
333 3 3 BBW WWB BWB 3 3 BBW WWB BWW 3 3 BBW WWB WBB 3 3 BBW WWB WBW 3 3 BBW WWB WWB 3 3 BBW WWB WWW 3 3 BBW WWW BBB 3 3 BBW WWW BBW 3 3 BBW WWW BWB 3 3 BBW WWW BWW 3 3 BBW WWW WBB 3 3 BBW WWW WBW 3 3 BBW WWW WWB 3 3 BBW WWW WWW 3 3 BWB BBB BBB 3 3 BWB BBB BBW 3 3 BWB BBB BWB 3 3 BWB BBB BWW 3 3 BWB ...
output:
YES 3 DDRR DRDR RDRD NO NO NO NO NO YES 3 DDRR DRRD RDRD NO NO NO NO NO NO NO NO NO YES 3 DDRR RDDR RRDD NO NO NO NO NO YES 3 DDRR RDRD RRDD NO NO NO NO NO NO NO NO NO NO NO NO NO YES 3 DRRD RDRD RRDD NO NO NO NO NO YES 3 DRDR RDRD RRDD NO NO NO YES 2 DRRD RDRD NO NO NO NO NO NO NO NO NO YES 2 DRDR ...
result:
ok ok (333 test cases)
Test #5:
score: 0
Accepted
time: 2ms
memory: 4164kb
input:
266 3 3 WWB WWW WWW 3 3 WWW BBB BBB 3 3 WWW BBB BBW 3 3 WWW BBB BWB 3 3 WWW BBB BWW 3 3 WWW BBB WBB 3 3 WWW BBB WBW 3 3 WWW BBB WWB 3 3 WWW BBB WWW 3 3 WWW BBW BBB 3 3 WWW BBW BBW 3 3 WWW BBW BWB 3 3 WWW BBW BWW 3 3 WWW BBW WBB 3 3 WWW BBW WBW 3 3 WWW BBW WWB 3 3 WWW BBW WWW 3 3 WWW BWB BBB 3 3 WWW ...
output:
NO NO NO NO YES 3 DRDR DRRD RRDD NO NO NO NO NO YES 1 RRDD NO NO NO NO NO NO NO NO NO NO NO NO NO YES 3 DDRR DRRD RRDD NO NO NO NO NO YES 5 DDRR DRDR RDRD RDRD RRDD NO NO NO YES 2 DDRR DRRD NO NO NO NO NO NO NO NO NO YES 4 DDRR DRDR RDRD RDRD NO NO NO NO NO NO NO NO NO YES 2 DRDR DRRD NO NO NO NO NO...
result:
ok ok (266 test cases)
Test #6:
score: 0
Accepted
time: 2ms
memory: 3952kb
input:
245 4 2 WW BB WB BW 4 2 WW BB WB WB 4 2 WW BB WB WW 4 2 WW BB WW BB 4 2 WW BB WW BW 4 2 WW BB WW WB 4 2 WW BB WW WW 4 2 WW BW BB BB 4 2 WW BW BB BW 4 2 WW BW BB WB 4 2 WW BW BB WW 4 2 WW BW BW BB 4 2 WW BW BW BW 4 2 WW BW BW WB 4 2 WW BW BW WW 4 2 WW BW WB BB 4 2 WW BW WB BW 4 2 WW BW WB WB 4 2 WW B...
output:
NO NO YES 3 DDDR DRDD RDDD NO YES 3 DDRD DRDD RDDD NO NO NO NO NO YES 3 DDDR DDRD RDDD NO YES 1 RDDD NO NO NO NO NO NO NO NO NO NO NO YES 2 DDDR DRDD NO NO NO NO NO YES 2 DDRD DRDD NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES 2 DDDR DDRD NO NO NO NO NO YES 0 YES 0 NO NO NO NO NO NO NO NO N...
result:
ok ok (245 test cases)
Test #7:
score: 0
Accepted
time: 2ms
memory: 3944kb
input:
200 5 3 BBB BBB WBW BBW BBW 5 3 BBB BBB WBW BBW BWB 5 3 BBB BBB WBW BBW BWW 5 3 BBB BBB WBW BBW WBB 5 3 BBB BBB WBW BBW WBW 5 3 BBB BBB WBW BBW WWB 5 3 BBB BBB WBW BBW WWW 5 3 BBB BBB WBW BWB BBB 5 3 BBB BBB WBW BWB BBW 5 3 BBB BBB WBW BWB BWB 5 3 BBB BBB WBW BWB BWW 5 3 BBB BBB WBW BWB WBB 5 3 BBB ...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok ok (200 test cases)
Test #8:
score: 0
Accepted
time: 2ms
memory: 4164kb
input:
200 5 4 BWWB WBWW WBWW WBWW WBBW 5 4 BWWB WBWW WBWW WBWW WBWB 5 4 BWWB WBWW WBWW WBWW WBWW 5 4 BWWB WBWW WBWW WBWW WWBB 5 4 BWWB WBWW WBWW WBWW WWBW 5 4 BWWB WBWW WBWW WBWW WWWB 5 4 BWWB WBWW WBWW WBWW WWWW 5 4 BWWB WBWW WBWW WWBB BBBB 5 4 BWWB WBWW WBWW WWBB BBBW 5 4 BWWB WBWW WBWW WWBB BBWB 5 4 BW...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES 8 DDDDRRR DDDRRDR DDDRRDR DDRDRDR DDRRDRD RRDDRDD RRDDRDD RRDRDDD NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES 6 DDDDRRR DDRDRDR DDRRDDR RRDDRDD RRDDRDD RRDRDDD NO NO NO NO NO NO NO NO NO YES 8 DDDDRRR DDDRDRR DDDRRDR DDRDRDR DDR...
result:
ok ok (200 test cases)
Test #9:
score: -100
Wrong Answer
time: 17ms
memory: 4444kb
input:
5 200 200 WBWWWBWBWWWWBWWWBBBBBBWBWWBWWBBWBWWBWBBBWBBWBBWBWBBWWWWWWBWWWBBWBWBWBWBBWBWWBWWBWBBBWWWBWBBWWBBBBBWWBBBBWWBBWBWWWBBWBWBWWWWBBWBWWBWWWWWBWWBBBBBWBBWBWWWWWBWWWBWBWWBBBBWWBWWWWBWBBWBWBBWWBWWBBWBWBWWBWBWB BBWBBBBBWBWWWWWWWWWWBBWWWWBWWBWWBBBBBWWWBWBWWBBWBBWWBBBBBWWBWBWBWWBWBWBBBBWWWWBWBBBBBWBBB...
output:
YES 802 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDRDRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
result:
wrong answer Integer 802 violates the range [0, 400] (test case 1)