QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#604778#8816. Solar Panel Grid Optimizationucup-team173WA 0ms3508kbC++203.4kb2024-10-02 13:52:022024-10-02 13:52:02

Judging History

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

  • [2024-10-02 13:52:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3508kb
  • [2024-10-02 13:52:02]
  • 提交

answer

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

using ll = long long;

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    vector ve(n, vector<int>(n));
    vector goal(n, vector<int>(n));
    vector<int> parity(n);
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < n; j++) {
            ve[i][j] = s[j] - '0';
        }
    }
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < n; j++) {
            goal[i][j] = s[j] - '0';
        }
    }
    vector<pair<int, int>> ans;
    auto row = [&](int i) {
        ans.push_back({0, i});
        int temp = ve[i][0];
        for(int j = 0; j < n - 1; j++) {
            ve[i][j] = ve[i][j + 1];
        }
        ve[i][n - 1] = temp;
    };
    auto col = [&](int j) {
        ans.push_back({1, j});
        int temp = ve[n - 1][j];
        for(int i = n - 1; i > 0; i--) {
            ve[i][j] = ve[i - 1][j];
        }
        ve[0][j] = temp ^ 1;
    };
    auto print = [&](vector<vector<int>> &v) {
        cout << "-------------------\n";
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                cout << v[i][j];
            }
            cout << '\n';
        }
    };
    int cnt = 0;
    for(int j = 0; j < n; j++) cnt += ve[n - 1][j];
    while(cnt < n) {
        while(ve[n - 1][n - 1]) row(n - 1);
        while(ve[n - 1][n - 1] == 0) col(n - 1);
        cnt++;
    }
    for(int i = 0; i < n; i++) {
        if(ve[n - 1][n - 1] == 0) row(n - 1);
        col(n - 1);
    }
    while(ve[n - 1][0]) row(n - 1), col(n - 1);
    for(int i = 0; i < n; i++) col(n - 1);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            parity[i] ^= ve[i][j] ^ goal[i][j];
        }
    }
    for(int i = n - 2; i >= 0; i--) {
        if(!parity[i]) row(n - 1);
        col(n - 1);
    }
    parity.assign(n, 0);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            parity[i] ^= ve[i][j] ^ goal[i][j];
        }
    }
    assert(*max_element(parity.begin(), parity.begin() + n - 1) == 0);
    print(ve);
    if(parity[n - 1]) {
        for(int i = 0; i < n - 1; i++) col(n - 1), row(n - 1);
        if(n % 2 == 0) col(n - 1);
        for(int i = 0; i < n - 1; i++) row(n - 1), col(n - 1);
        for(int i = 0; i < n; i++) col(n - 1);
    }
    parity.assign(n, 0);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            parity[i] ^= ve[i][j] ^ goal[i][j];
        }
    }
    assert(*max_element(parity.begin(), parity.begin() + n) == 0);
    // print(ve);
    for(int j = 0; j < n - 1; j++) {
        vector<int> tmp;
        for(int i = 0; i < n; i++) {
            if(ve[i][n - 1] == goal[i][j]) row(i);
            else tmp.push_back(i);
        }
        for(int i = 0; i < n; i++) col(n - 1);
        for(int i : tmp) row(i);
        // print(ve);
    }
    if(ve[0][n - 1] != goal[0][n - 1]) {
        for(int i = 0; i < n; i++) col(n - 1);
    }
    // print(ve);
    cout << ans.size() << '\n';
    for(auto [x, y] : ans) {
        if(x == 0) cout << "row " << y + 1 << '\n';
        else cout << "column " << y + 1 << '\n';
    }
    return 0;
}
/*
4
0010
1011
1101
0011

0010
0011
0110
0000



*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3508kb

input:

4
1011
1100
0100
1011

1001
0110
0110
1001

output:

-------------------
1010
1100
0101
0011
51
row 4
row 4
column 4
column 4
column 4
column 4
column 4
column 4
column 4
row 4
column 4
row 4
column 4
row 4
column 4
column 4
column 4
column 4
column 4
row 4
column 4
column 4
column 4
row 2
row 4
column 4
column 4
column 4
column 4
row 1
row 3
column 4...

result:

wrong output format Expected integer, but "-------------------" found