QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#883998#9926. Flipping PathsLuminousYTWA 0ms3584kbC++202.6kb2025-02-05 20:38:572025-02-05 20:38:59

Judging History

This is the latest submission verdict.

  • [2025-02-05 20:38:59]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3584kb
  • [2025-02-05 20:38:57]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

int main() {
    int T;
    cin >> T;
    while (T--) {
        int n, m;
        cin >> n >> m;
        vector<string> grid(n);
        for (int i = 0; i < n; ++i) cin >> grid[i];

        bool all_white = true, all_black = true;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (grid[i][j] == 'W') all_black = false;
                else all_white = false;
            }
        }
        if (all_white || all_black) {
            cout << "YES\n0\n";
            continue;
        }

        if (n == 1 || m == 1) {
            int total = n * m;
            int black = 0;
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < m; ++j)
                    black += (grid[i][j] == 'B');
            bool possible = false;
            if (total % 2 == 0) {
                if (black == 0 || black == total) possible = true;
                else if (total - black == 0 || total - black == total) possible = true;
            } else {
                if (black == 0 || black == total) possible = true;
                else if (total - black == 0 || total - black == total) possible = true;
            }
            if (!possible) {
                cout << "NO\n";
                continue;
            }
            cout << "YES\n1\n";
            if (n == 1) cout << string(m-1, 'R') << '\n';
            else cout << string(n-1, 'D') << '\n';
            continue;
        }

        bool found = false;
        for (int target = 0; target < 2; ++target) { // 0: B, 1: W
            vector<int> diag_cnt(n + m, 0);
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    bool is_error = (target == 0) ? (grid[i][j] == 'W') : (grid[i][j] == 'B');
                    int k = i + j;
                    if (is_error) diag_cnt[k]++;
                }
            }
            bool valid = true;
            for (int k = 0; k < n + m - 1; ++k) {
                if (diag_cnt[k] % 2 != 0) {
                    valid = false;
                    break;
                }
            }
            if (valid) {
                found = true;
                break;
            }
        }

        if (found) {
            string path1 = string(m-1, 'R') + string(n-1, 'D');
            string path2 = string(n-1, 'D') + string(m-1, 'R');
            cout << "YES\n2\n" << path1 << '\n' << path2 << '\n';
        } else {
            cout << "NO\n";
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 0ms
memory: 3584kb

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

result:

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