QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#835245#9926. Flipping Pathsucup-team5318#WA 1ms3832kbC++141.8kb2024-12-28 10:41:372024-12-28 10:41:47

Judging History

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

  • [2024-12-28 10:41:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3832kb
  • [2024-12-28 10:41:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define pb emplace_back
#define fi first
#define se second
using vi=vector<int>;
using pi=pair<int,int>;

void solve(){
	int n,m; cin>>n>>m;
	vector<vi> a(n, vi(m));
	vi s(n+m);
	rep(i,0,n-1){
		string str; cin>>str;
		rep(j,0,m-1){
			a[i][j]=(str[j]=='B');
		}
	}
	rep(i,0,n-1){
		rep(j,0,m-1){
			s[i+j]^= a[i][j];
		}
	}

	vector<vi> ans;
	auto opt=[&](vi d){
		ans.pb(d);
		
		int c=0;
		rep(i,0,n-1){
			a[i][c]^= 1;
			while(c<d[i+1]){
				c++;
				a[i][c]^= 1;
			}
		}
	};

	auto slv=[&](int op){
		ans.clear();
		rep(i,1,n+m-1){
			if(op==0 && s[i]!=s[i-1]){
				return false;
			}
			if(op==1 && s[i]==s[i-1]){
				return false;
			}
		}
		per(i,n-1,-(m-2)){// i=x-y
			vi d(n+1, m-1);
			d[0]=0;
			rep(x,1,n-1){
				int y=x-i;
				if(y<0){
					d[x]=0;
				}
				else if(y>=m-1){
					d[x]=m-1;
				}
				else{
					if(a[x][y]!=op){
						d[x]=y;
					}
					else{
						d[x]=y+1;
					}
				}
			}
			opt(d);
		}
		if(a[0][m-1]!=op){
			vi d(n+1, m-1);
			d[0]=0;
			opt(d);
		}
		return true;
	};
	
	bool ok=0;
	rep(c,0,1){
		if(slv(c)){
			ok=1;
			break;
		}
	}

	if(!ok){
		cout<< "NO\n";
		return;
	}
	cout<< "YES\n";
	cout<< ans.size() <<'\n';
	for(auto x:ans){
		//for(int y:x){
		//	cout<< y <<' ';
		//}
		//cout<<endl;
		string output;
		int c=0;
		rep(i,1,n){
			while(c<x[i]){
				output+= 'R';
				c++;
			}
			if(i<n){
				output+= 'D';
			}
		}
		cout<< output <<'\n';
	}
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);
	#ifndef ONLINE_JUDGE
	assert(freopen(".in","r",stdin));
	assert(freopen(".out","w",stdout));
	#endif
	
	int t; cin>>t;
	while(t--){
		solve();
	}
}

详细

Test #1:

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

input:

4
3 3
WBB
BWB
BBW
1 5
WWWWW
2 2
BB
BB
4 1
W
B
B
W

output:

YES
4
DDRR
RDRD
RDRD
RRDD
YES
4
RRRR
RRRR
RRRR
RRRR
YES
2
RD
RD
NO

result:

ok ok (4 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3540kb

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:

NO
NO
YES
2
R
R
YES
2
R
R
NO
NO
YES
1
D
YES
2
D
D
NO
NO
YES
2
RR
RR
NO
NO
NO
NO
YES
2
RR
RR
YES
2
RD
RD
NO
NO
NO
NO
NO
YES
2
DR
RD
NO
NO
YES
2
DR
RD
NO
NO
NO
NO
NO
YES
2
RD
RD
NO
NO
YES
2
DD
DD
NO
NO
NO
NO
YES
2
DD
DD
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
4
RRR
RRR
RRR
RRR
NO
NO
NO
NO
YES
4
RRR
RRR
RRR
...

result:

wrong answer Jury has answer but participant has not. (test case 1)