QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#835334#9926. Flipping Pathsucup-team1004#RE 1ms3972kbC++173.8kb2024-12-28 11:20:382024-12-28 11:20:50

Judging History

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

  • [2024-12-28 11:20:50]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3972kb
  • [2024-12-28 11:20:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
template<class T>
extern ostream& operator << (ostream &out,deque<T> a){
	out<<'[';
	for(auto x:a)out<<x<<',';
	return out<<']';
}
using ll=long long;
using ull=unsigned long long;
const int N=205;
int T,n,m,a[N][N];
char str[N];
bool solve(){
	string s1,s2;
	deque<pair<int,string>>p,q;
	vector<string>ans;
	int n=::n,m=::m;
	static int b[N],c[N];
	if(a[1][n]){
		p.push_front({1,s1});
		q.push_front({1,s2});
	}
	for(;;){
		// debug(n,m,p,q);
		if(n==1){
			fill(b,b+1+m,0);
			for(auto [u,v]:p)b[u]^=1;
			for(int i=1;i<=m;i++)b[i]^=b[i-1];
			for(int i=1;i<=m;i++){
				if(b[i]!=a[i][1])return 0;
			}
			break;
		}
		if(m==1){
			fill(b,b+1+n,0);
			for(auto [u,v]:q)b[u]^=1;
			for(int i=1;i<=n;i++)b[i]^=b[i-1];
			for(int i=1;i<=n;i++){
				if(b[i]!=a[1][i])return 0;
			}
			break;
		}
		for(int i=1;i<=m;i++)b[i]=a[i][n]^a[i-1][n];
		for(int i=1;i<=n;i++)c[i]=a[m][i]^a[m][i-1];
		// debug(ary(b,1,m),ary(c,1,n));
		auto match=[&](){
			if(p.empty()){
				p.push_front({1,s1});
				p.push_front({1,s1});
			}
			if(q.empty()){
				q.push_front({1,s2});
				q.push_front({1,s2});
			}
			ans.push_back(p.back().second);
			b[p.back().first]^=1;
			for(int t=m-p.back().first;t--;)ans.back()+='R';
			c[q.back().first]^=1;
			for(int t=n-q.back().first;t--;)ans.back()+='D';
			reverse(all(q.back().second));
			ans.back()+=q.back().second;
			// debug(ans);
			p.pop_back();
			q.pop_back();
		};
		int cur=a[m][n];
		if((!p.empty()&&p.back().first==m)||(!q.empty()&&q.back().first==n))match(),cur^=1;
		if(cur)match();
		// debug(p,q);
		auto run=[&](int *b,deque<pair<int,string>>&p,string s,char c,char e,int n){
			// debug(ary(b,1,n),p);
			deque<pair<int,string>>q;
			// debug(p,n);
			// debug(p);
			for(int i=n;i>=2;i--){
				if(!p.empty())assert(p.back().first<=i-1);
				if(!p.empty()&&p.back().first==i-1){
					q.push_front({p.back().first,p.back().second+e});
					b[i-1]^=1,b[i]^=1;
					p.pop_back();
				}
				if(b[i]){
					if(p.empty()){
						p.push_front({1,s});
						p.push_front({1,s});
					}
					b[i]^=1,b[p.back().first]^=1;
					auto res=p.back().second;
					for(int t=i-1-p.back().first;t--;)res+=c;
					q.push_front({i-1,res+e});
					p.pop_back();
				}
			}
			if(b[1]!=p.size()%2)return 0;
			for(auto [u,v]:p){
				assert(u==1);
				q.push_front({u,v+e});
			}
			p=q;
			// debug(p);
			// debug(q);
			return 1;
		};
		if(!run(b,p,s1,'R','D',m))return 0;
		if(!run(c,q,s2,'D','R',n))return 0;
		// debug(n,m,p,q,ans);
		if(p.size()%2!=q.size()%2)return 0;
		s1+='D',s2+='R';
		n--,m--;
	}
	for(;p.size()<q.size();)p.push_front({1,s1});
	for(;p.size()>q.size();)q.push_front({1,s2});
	for(;!p.empty();){
		ans.push_back(p.back().second);
		b[p.back().first]^=1;
		for(int t=m-p.back().first;t--;)ans.back()+='R';
		c[q.back().first]^=1;
		for(int t=n-q.back().first;t--;)ans.back()+='D';
		reverse(all(q.back().second));
		ans.back()+=q.back().second;
		p.pop_back();
		q.pop_back();
	}
	puts("YES");
	cout<<ans.size()<<'\n';
	for(auto s:ans)cout<<s<<'\n';
	return 1;
}
void work(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",str+1);
		for(int j=1;j<=m;j++)a[j][n-i+1]=str[j]=='W';
	}
	if(n==1||m==1){
		bool flag=1;
		for(int i=1;i<=m;i++){
			for(int j=1;j<=n;j++){
				flag&=a[i][j]==a[1][1];
			}
		}
		if(flag)puts("YES\n0");
		else puts("NO");
		return;
	}
	if(solve())return;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++)a[i][j]^=1;
	}
	if(solve())return;
	puts("NO");
}
int main(){
	for(scanf("%d",&T);T--;)work();
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3672kb

input:

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

output:

YES
2
RRDD
DDRR
YES
0
YES
0
NO

result:

ok ok (4 test cases)

Test #2:

score: 0
Accepted
time: 1ms
memory: 3744kb

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
RD
DR
NO
NO
YES
2
RD
DR
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
RRD
RDR
...

result:

ok ok (323 test cases)

Test #3:

score: 0
Accepted
time: 1ms
memory: 3740kb

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
RRRD
RRDR
DRRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
2
RRDR
DRRR
NO
NO
NO
YES
1
DRRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
2
RRRD
DRRR
NO
NO
YES
2
RRRD
DRRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
1
DRRR
NO
NO
NO
YES
2
RRDR
DRRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
3
RRRD
RRDR
DRR...

result:

ok ok (278 test cases)

Test #4:

score: 0
Accepted
time: 1ms
memory: 3964kb

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
RDRD
DRDR
DDRR
NO
NO
NO
NO
NO
YES
3
RDDR
DRDR
DDRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
3
RRDD
RDDR
DDRR
NO
NO
NO
NO
NO
YES
3
RRDD
RDRD
DDRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
3
RRDD
RDDR
DRDR
NO
NO
NO
NO
NO
YES
3
RRDD
RDRD
DRDR
NO
NO
NO
YES
2
RDDR
DRDR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
2
RDRD
...

result:

ok ok (333 test cases)

Test #5:

score: 0
Accepted
time: 1ms
memory: 3972kb

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
RRDD
DRRD
DRDR
NO
NO
NO
NO
NO
YES
1
RRDD
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
3
RRDD
DRRD
DDRR
NO
NO
NO
NO
NO
YES
3
RRDD
DRDR
DDRR
NO
NO
NO
YES
2
DRRD
DDRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
2
DRDR
DDRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
2
DRRD
DRDR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
0
Y...

result:

ok ok (266 test cases)

Test #6:

score: 0
Accepted
time: 1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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: -100
Runtime Error

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:


result: