QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#835225 | #9926. Flipping Paths | ucup-team5657# | WA | 21ms | 3888kb | C++14 | 2.6kb | 2024-12-28 10:34:25 | 2024-12-28 10:34:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 205;
int T, n, m, f[N << 1], g[N << 1];
string s[N];
vector <pair <int, int> > vec[N << 1];
inline void op(int i, int j) {
s[i][j] = (s[i][j] == 'W') ? 'B' : 'W';
}
inline void solve() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> s[i];
s[i] = "#" + s[i];
}
for (int i = 0; i <= n + m; ++i) {
vec[i].clear();
f[i] = 0;
g[i] = 0;
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (s[i][j] == 'W') {
f[i + j] ^= 1;
} else {
g[i + j] ^= 1;
}
}
}
bool flg1 = 1, flg2 = 1;
for (int i = 3; i <= n + m; ++i) {
if (f[i] != f[i - 1]) {
flg1 = 0;
}
if (g[i] != g[i - 1]) {
flg2 = 0;
}
}
if (!flg1 && !flg2) {
cout << "NO\n";
return;
}
cout << "YES\n";
char col = flg1 ? 'B' : 'W';
bool flg = (s[1][1] != col);
if (flg) {
for (int i = 1; i <= n; ++i) {
op(i, 1);
}
for (int i = 2; i <= m; ++i) {
op(n, i);
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (s[i][j] != col) {
vec[j - i + n].emplace_back(make_pair(i + 1, j));
op(i, j), op(i + 1, j - 1);
}
}
}
int cnt = 0;
for (int i = 0; i <= n + m; ++i) {
if (!vec[i].size()) {
continue;
}
++cnt;
}
if (flg) {
cout << (cnt << 1 | 1) << "\n";
for (int i = 1; i < n; ++i) {
cout << "D";
}
for (int i = 2; i <= m; ++i) {
cout << "R";
}
cout << "\n";
} else {
cout << (cnt << 1) << "\n";
}
for (int i = 0; i <= n + m; ++i) {
if (!vec[i].size()) {
continue;
}
int x = 1, y = 1;
for (auto u: vec[i]) {
while (x < u.first - 1) {
cout << "D";
++x;
}
while (y < u.second - 1) {
cout << "R";
++y;
}
cout << "DR";
x = u.first, y = u.second;
}
while (x < n) {
cout << "D";
++x;
}
while (y < m) {
cout << "R";
++y;
}
cout << "\n";
x = 1, y = 1;
for (auto u: vec[i]) {
while (x < u.first - 1) {
cout << "D";
++x;
}
while (y < u.second - 1) {
cout << "R";
++y;
}
cout << "RD";
x = u.first, y = u.second;
}
while (x < n) {
cout << "D";
++x;
}
while (y < m) {
cout << "R";
++y;
}
cout << "\n";
}
}
int main() {
#ifdef LOCAL
assert(freopen("test.in", "r", stdin));
assert(freopen("test.out", "w", stdout));
#endif
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> T;
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
input:
4 3 3 WBB BWB BBW 1 5 WWWWW 2 2 BB BB 4 1 W B B W
output:
YES 6 DDRR DRDR DRDR RDRD RDRD RRDD YES 1 RRRR YES 0 NO
result:
ok ok (4 test cases)
Test #2:
score: 0
Accepted
time: 1ms
memory: 3808kb
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 1 R YES 0 NO NO YES 1 D YES 0 NO NO NO NO NO NO YES 1 RR YES 0 NO YES 3 DR DR RD NO YES 1 DR NO YES 2 DR RD NO NO YES 2 DR RD NO YES 1 DR NO YES 3 DR DR RD NO YES 0 YES 0 NO NO NO NO NO NO YES 1 DD YES 0 NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES 1 RRR YES 0 NO NO NO NO NO YES 5 D...
result:
ok ok (323 test cases)
Test #3:
score: 0
Accepted
time: 1ms
memory: 3808kb
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 4 DRRR RDRR RDRR RRDR NO NO NO YES 1 DRRR NO NO NO NO NO NO NO NO NO NO NO NO NO YES 6 DRRR RDRR RDRR RRDR RRDR RRRD NO NO YES 6 DRRR RDRR RDRR RRDR RRDR RRRD NO NO NO NO NO NO NO NO NO NO NO NO NO YES 1 DRRR NO NO NO YES 4 DRRR R...
result:
ok ok (278 test cases)
Test #4:
score: 0
Accepted
time: 1ms
memory: 3648kb
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 DRDR RDDR NO NO NO NO NO NO NO NO NO YES 5 DDRR DRDR DRRD RDRD 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 7 DDRR DDRR DRDR DRDR DRRD RDRD RRDD NO NO NO NO NO YES 5 DDRR DDRR DRDR RDRD RRDD NO NO NO YES 2 DRDR RDD...
result:
ok ok (333 test cases)
Test #5:
score: 0
Accepted
time: 1ms
memory: 3512kb
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 7 DDRR DDRR DRDR DRDR RDDR RDRD RRDD NO NO NO NO NO YES 7 DDRR DDRR DRDR DRDR RDRD RDRD RRDD NO NO NO NO NO NO NO NO NO NO NO NO NO YES 5 DDRR DRDR RDDR RDRD RRDD NO NO NO NO NO YES 5 DDRR DRDR RDRD RDRD RRDD NO NO NO YES 4 DDRR DRDR DRDR DRRD NO NO NO NO NO NO NO NO NO YES 2 DDRR DR...
result:
ok ok (266 test cases)
Test #6:
score: 0
Accepted
time: 0ms
memory: 3812kb
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 5 DDDR DDDR DDRD DRDD RDDD NO NO NO NO NO YES 5 DDDR DDRD DRDD DRDD RDDD NO YES 7 DDDR DDDR DDRD DDRD DRDD DRDD RDDD NO NO NO NO NO NO NO NO NO NO NO YES 4 DDDR DDRD DDRD 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 DD...
result:
ok ok (245 test cases)
Test #7:
score: 0
Accepted
time: 0ms
memory: 3556kb
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: 1ms
memory: 3840kb
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 10 DDDDRRR DDDRDRR DDDRDRR DDRDRDR DDRDDRR DRDDDRR DRDRDRD RDRDRDD RDRDRDD RRDRDDD NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES 10 DDDDRRR DDDRDRR DDDRDRR DDRDRDR DDRDRDR DRDDRRD DRDRDRD RDRDRDD RDRDRDD RRDRDDD NO NO NO NO NO NO ...
result:
ok ok (200 test cases)
Test #9:
score: -100
Wrong Answer
time: 21ms
memory: 3888kb
input:
5 200 200 WBWWWBWBWWWWBWWWBBBBBBWBWWBWWBBWBWWBWBBBWBBWBBWBWBBWWWWWWBWWWBBWBWBWBWBBWBWWBWWBWBBBWWWBWBBWWBBBBBWWBBBBWWBBWBWWWBBWBWBWWWWBBWBWWBWWWWWBWWBBBBBWBBWBWWWWWBWWWBWBWWBBBBWWBWWWWBWBBWBWBBWWBWWBBWBWBWWBWBWB BBWBBBBBWBWWWWWWWWWWBBWWWWBWWBWWBBBBBWWWBWBWWBBWBBWWBBBBBWWBWBWBWWBWBWBBBBWWWWBWBBBBBWBBB...
output:
YES 792 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDRDRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
result:
wrong answer Integer 792 violates the range [0, 400] (test case 1)