QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#835247 | #9926. Flipping Paths | ucup-team5318# | WA | 1ms | 3620kb | C++14 | 1.9kb | 2024-12-28 10:43:20 | 2024-12-28 10:43:22 |
Judging History
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), c(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];
c[i+j]^= 1;
}
}
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-2){
if(op==0 && s[i]!=s[i-1]){
return false;
}
}
rep(i,0,n+m-2){
if(op==1 && s[i]!=c[i]){
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: 0ms
memory: 3620kb
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: 3596kb
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 1 R NO NO YES 2 R R YES 1 D NO NO YES 2 D D YES 3 RR RR RR NO NO NO NO NO NO YES 2 RR RR YES 2 RD RD NO YES 3 RD RD RD NO YES 3 DR RD RD NO YES 2 DR RD NO NO YES 2 DR RD NO NO NO NO NO YES 2 RD RD YES 3 DD DD DD NO NO NO NO NO NO YES 2 DD DD YES 3 RRR RRR RRR NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
wrong answer Jury has answer but participant has not. (test case 28)