QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#831663#9926. Flipping Pathsucup-team4479#WA 1ms3828kbC++235.3kb2024-12-25 15:57:162024-12-25 15:57:16

Judging History

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

  • [2024-12-25 15:57:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2024-12-25 15:57:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 205;
bool mp[N][N], vis[N][N], rev;
int n, m;
bool work(int goal) {
    vector <string> ans;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            vis[i][j] = mp[i][j];
    // cout << goal << ":" << endl;
    for (int d = m - 1; d >= 2; --d) {
        string s = "";
        for (int k = 1; k <= d - 1; ++k) {
            s = s + 'R';
            vis[1][k] ^= 1;
        }
        // cout << s << endl;
        vis[1][d] ^= 1;
        for (int i = 1; i < n; ++i) {
            int j = i + d;
            if (j > m) continue;
            if (vis[i][j] == goal) {
                s += "DR";
                vis[i + 1][j - 1] ^= 1;
                vis[i + 1][j] ^= 1;
            } else {
                s = s + "RD";
                vis[i][j] ^= 1;
                vis[i + 1][j] ^= 1;
            }
        }
        for (int i = m - d + 1; i < n; ++i) {
            s += 'D';
            vis[i + 1][m] ^= 1;
        }
        for (int j = n + d - 1; j < m; ++j) {
            s += 'R';
            vis[n][j + 1] ^= 1;
        }
        // cout << s << endl;
        // for (int i = 1; i <= n; ++i) {
        //     for (int j = 1; j <= m; ++j)
        //         cout << vis[i][j] << " ";
        //     cout << endl;
        // }
        ans.push_back(s);
    }
    for (int d = n - 1; d >= 2; --d) {
        string s = "";
        for (int k = 1; k <= d - 1; ++k) {
            s += 'D';
            vis[k][1] ^= 1;
        }
        vis[d][1] ^= 1;
        for (int i = d + 1; i <= n; ++i) {
            int j = i - d;
            if (j < 1) continue;
            if (vis[i][j] == goal) {
                s += "RD";
                vis[i - 1][j + 1] ^= 1;
                vis[i][j + 1] ^= 1;
            } else {
                s += "DR";
                vis[i][j] ^= 1;
                vis[i][j + 1] ^= 1;
            }
        }
        for (int j = n - d + 1; j < m; ++j) {
            s += 'R';
            vis[n][j + 1] ^= 1;
        }
        // for (int j = m + d - 1; )
        // cout << s << endl;
        // for (int i = 1; i <= n; ++i) {
        //     for (int j = 1; j <= m; ++j)
        //         cout << vis[i][j] << " ";
        //     cout << endl;
        // }
        ans.push_back(s);
    }
    // for (auto s : ans) {
    //     cout << s << endl;
    // }
    // for (int i = 1; i <= n; ++i) {
    //     for (int j = 1; j <= m; ++j)
    //         cout << vis[i][j] << " ";
    //     cout << endl;
    // }
    for (int i = m; i >= n + 1; --i)
        if (vis[n][i] != vis[n][i - 1]) return false;
    int t = (vis[1][2] ^ goal) + (vis[2][1] ^ goal);
    for (int i = 2; i < n; ++i)
        if ((((vis[i][i + 1] ^ goal) + (vis[i + 1][i] ^ goal)) & 1) != (t & 1)) return false;
    for (int i = 1; i < n; ++i)
        if (((t & 1) ^ vis[i][i]) != goal) return false;
    // cout << t << endl;
    if (t) {
        vector <string> s(t, "");
        for (int i = 1; i < n; ++i) {
            if ((vis[i][i + 1] != goal) && (vis[i + 1][i] != goal)) {
                s[0] += "RD";
                s[1] += "DR";
            } else if ((vis[i][i + 1] == goal) && (vis[i + 1][i] == goal)) {
                s[0] += "RD";
                s[1] += "RD";
            } else s[0] += vis[i][i + 1] != goal ? "RD" : "DR";
        }
        for (int i = n; i < m; ++i)
            for (int j = 0; j < s.size(); ++j)
                s[j] += 'R';
        ans.insert(ans.end(), s.begin(), s.end());
    }
    cout << "YES" << endl;
    cout << ans.size() << endl;
    for (string s : ans) {
        int x = 1, y = 1;
        mp[x][y] ^= 1;
        for (int i = 0; i < s.length(); ++i) {
            if (rev) cout << ((s[i] == 'R') ? 'D' : 'R');
            else cout << s[i];
            if (s[i] == 'D') x++;
            else y++;
            mp[x][y] ^= 1;
        }
        cout << endl;
    }
    // for (int i = 1; i <= n; ++i)
    //     for (int j = 1; j <= m; ++j)
    //         assert(!(mp[i][j] ^ goal));
    return true;
}
void solve() {
    string s;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> s;
        for (int j = 1; j <= m; ++j)
            mp[i][j] = s[j - 1] == 'B';
    }
    rev = 0;
    if (n > m) {
        rev = 1;
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j < i; ++j)
                swap(mp[i][j], mp[j][i]);
        swap(n, m);
    }
    if (n == 1) {
        bool flag = 1;
        for (int i = 2; i <= m; ++i)
            if (mp[1][i] != mp[1][i - 1]) {
                cout << "NO" << endl;
                return;
            }
        cout << "YES\n0" << endl;
        return;
    }
    // for (int i = 1; i <= n; ++i) {
    //     for (int j = 1; j <= m; ++j)
    //         cout << mp[i][j] << " ";
    //     cout << endl;
    // }
    if (work(0) || work(1)) return;
    else {
        cout << "NO" << endl;
        return;
    }
}
int main() {
    cin.tie(nullptr) -> ios::sync_with_stdio(false);
    cout.tie(0);
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}
/*
7
3 3
WBB
BWB
BBW
1 5
WWWWW
2 2
BB
BB
4 1
W
B
B
W
4 3
WBW
WWW
WBB
BWW
6 4
WWWW
BBWB
BBWB
WWWB
WBBB
BWWW
6 3
WBW
WBB
BWW
BBW
BWW
WBW
*/

詳細信息

Test #1:

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

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: 1ms
memory: 3828kb

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
YES
0
YES
1
RD
YES
1
RD
YES
1
DR
YES
1
DR
YES
2
RD
DR
YES
2
RD
DR
YES
2
RD
DR
YES
2
RD
DR
YES
1
DR
YES
1
DR
YES
1
RD
YES
1
RD
YES
0
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
2
...

result:

wrong answer cell (2,2) contains different color with (1,1) after all ops. (test case 18)