QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#883772#9926. Flipping PathsLuminousYTWA 1ms3328kbC++202.1kb2025-02-05 18:45:162025-02-05 18:45:23

Judging History

This is the latest submission verdict.

  • [2025-02-05 18:45:23]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3328kb
  • [2025-02-05 18:45:16]
  • 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];

        int black = 0;
        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] == 'B') {
                    black++;
                    all_white = false;
                } else {
                    all_black = false;
                }
            }
        }

        if (all_white || all_black) {
            cout << "YES\n0\n";
            continue;
        }

        if (n == 1 || m == 1) {
            int total = n * m;
            bool possible = false;
            if (total % 2 == 0) {
                if (black == 0 || black == total) possible = true;
                else if (black == total || (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;
            }

            if (black == 0 || black == total) {
                cout << "YES\n0\n";
            } else {
                cout << "YES\n1\n";
                if (n == 1) cout << string(m-1, 'R') << '\n';
                else cout << string(n-1, 'D') << '\n';
            }
            continue;
        }

        int total = n * m;
        bool possible = false;
        if (total % 2 == 0) {
            if (black % 2 == 0) possible = true;
        } else {
            if (black % 2 == 1 || (total - black) % 2 == 0) possible = true;
        }

        if (!possible) {
            cout << "NO\n";
            continue;
        }

        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';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3328kb

input:

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

output:

NO
YES
0
YES
0
NO

result:

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