QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#836127#9926. Flipping Pathsucup-team6275#WA 1ms3840kbC++233.5kb2024-12-28 16:46:352024-12-28 16:46:36

Judging History

你现在查看的是最新测评结果

  • [2024-12-28 16:46:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3840kb
  • [2024-12-28 16:46:35]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for (int i = 0; i < (n); i += 1)
#define len(a) ((int)(a).size())

mt19937 rnd(234);
const ll inf = 1e18;

int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    int t;
    cin >> t;
    rep(itr, t) {
        int n, m;
        cin >> n >> m;
        vector<vector<int>> a(n, vector<int>(m));
        rep(i, n) {
            rep(j, m) {
                char c;
                cin >> c;
                a[i][j] = (c == 'B');
            }
        }
        int cnt0 = 0;
        int cnt1 = 0;
        rep(i, n) {
            rep(j, m) {
                if (a[i][j] == 0) {
                    cnt0 += 1;
                } else {
                    cnt1 += 1;
                }
            }
        }
        if (cnt0 == 0 or cnt1 == 0) {
            cout << "YES" << "\n";
            cout << 0 << "\n";
            continue;
        }
        if (n == 1 or m == 1) {
            cout << "NO" << "\n";
            continue;
        }
        vector<string> result;
        for (int x = -(m - 1); x <= n - 3; x += 1) {
            int i = 0;
            int j = 0;
            string s;
            a[i][j] ^= 1;
            while (i - j > x + 1) {
                s.push_back('R');
                j += 1;
                a[i][j] ^= 1;
            }
            while (i - j < x + 1) {
                s.push_back('D');
                i += 1;
                a[i][j] ^= 1;
            }
            while (j < m - 1 and i < n - 1) {
                if (a[i][j + 1] == 1) {
                    s.push_back('R');
                    j += 1;
                    a[i][j] ^= 1;
                    s.push_back('D');
                    i += 1;
                    a[i][j] ^= 1;
                } else {
                    s.push_back('D');
                    i += 1;
                    a[i][j] ^= 1;
                    s.push_back('R');
                    j += 1;
                    a[i][j] ^= 1;
                }
            }
            while (i < n - 1) {
                s.push_back('D');
                i += 1;
                a[i][j] ^= 1;
            }
            while (j < m - 1) {
                s.push_back('R');
                j += 1;
                a[i][j] ^= 1;
            }
            result.push_back(s);
        }
        if (a[0][0] != 0) {
            int i = 0;
            int j = 0;
            string s;
            a[i][j] ^= 1;
            while (i < n - 1) {
                s.push_back('D');
                i += 1;
                a[i][j] ^= 1;
            }
            while (j < m - 1) {
                s.push_back('R');
                j += 1;
                a[i][j] ^= 1;
            }
            result.push_back(s);
        }
        cnt0 = 0;
        cnt1 = 0;
        rep(i, n) {
            rep(j, m) {
                if (a[i][j] == 0) {
                    cnt0 += 1;
                } else {
                    cnt1 += 1;
                }
            }
        }
        if (cnt0 == 0 or cnt1 == 0) {
            cout << "YES" << "\n";
            cout << len(result) << "\n";
            for (auto s : result) {
                cout << s << "\n";
            }
        } else {
            cout << "NO" << "\n";
        }
    }
    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

YES
4
RRDD
DRDR
DRDR
DDRR
YES
0
YES
0
NO

result:

ok ok (4 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3840kb

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
YES
1
RD
NO
YES
1
DR
NO
NO
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
YES
3
RRD
DRR
DRR
NO
NO
NO
NO
NO
YES
3
RDR
DRR
DRR
NO
...

result:

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