QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#835662 | #9926. Flipping Paths | ucup-team5243# | WA | 1ms | 3672kb | C++17 | 2.1kb | 2024-12-28 13:32:52 | 2024-12-28 13:32:57 |
Judging History
answer
#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
const i64 INF = 1001001001001001001;
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
using namespace std;
void testcase(){
int H, W; cin >> H >> W;
vector<string> A(H); rep(y,H) cin >> A[y];
rep(t,2){
bool ok = false; {
vector<int> Q(H+W-1);
rep(y,H) rep(x,W) if(A[y][x] == 'W') Q[y+x] ^= 1;
if(Q == vector<int>(H+W-1,0)) ok = true;
if(Q == vector<int>(H+W-1,1)){
rep(y,H) rep(x,W) A[y][x] ^= 'B' ^ 'W';
ok = true;
}
}
if(!ok){
rep(y,H) rep(x,W) A[y][x] ^= 'B' ^ 'W';
continue;
}
rep(y,H) rep(x,W) A[y][x] = (A[y][x] == 'W' ? 1 : 0);
vector<string> ans;
for(int t=-(H-1); t<W-2; t++){
string f;
int y = 0, x = 0;
A[y][x] ^= 1;
rep(i,H+W-2){
if(x==W-1){ f.push_back('D'); y++; }
else if(y==H-1){ f.push_back('R'); x++; }
else if(x-y > t+1){ f.push_back('D'); y++; }
else if(x-y <= t){ f.push_back('R'); x++; }
else{
if(A[y+1][x]){ f.push_back('D'); y++; }
else { f.push_back('R'); x++; }
}
A[y][x] ^= 1;
}
ans.push_back(f);
}
if(A[0][W-1]) ans.push_back(string(W-1,'R') + string(H-1,'D'));
cout << "YES" << endl;
cout << ans.size() << endl;
for(auto& a : ans) cout << a << endl;
return;
}
cout << "NO" << endl;
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int T; cin >> T;
rep(t,T) testcase();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
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: 3672kb
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 2 RR RR NO NO NO NO NO NO YES 2 RR RR YES 2 RD RD NO YES 1 DR NO YES 1 RD NO YES 2 DR RD NO NO YES 2 DR RD NO YES 1 RD NO YES 1 DR NO YES 2 RD RD YES 2 DD DD NO NO NO NO NO NO YES 2 DD DD YES 2 RRR RRR NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES 2 RRR RRR YE...
result:
wrong answer cell (1,2) contains different color with (1,1) after all ops. (test case 19)