QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#604755#8816. Solar Panel Grid Optimizationucup-team173RE 0ms3620kbC++203.3kb2024-10-02 13:44:202024-10-02 13:44:21

Judging History

This is the latest submission verdict.

  • [2024-10-02 13:44:21]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3620kb
  • [2024-10-02 13:44:20]
  • Submitted

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);
    if(parity[n - 1]) {
        for(int i = 0; i < n; i++) col(n - 1);
        row(n - 1);
        col(n - 1);
        for(int i = 0; i < n; i++) col(n - 1);
        for(int i = 0; i < n - 1; i++) row(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



*/

詳細信息

Test #1:

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

input:

4
1011
1100
0100
1011

1001
0110
0110
1001

output:

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
column 4
column 4
column 4
row 1
row 2
...

result:

ok Accepted! 51 steps.

Test #2:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

3
110
111
101

111
010
111

output:

28
row 3
row 3
column 3
column 3
row 3
column 3
column 3
row 3
column 3
column 3
column 3
column 3
row 3
column 3
row 3
column 3
row 1
row 3
column 3
column 3
column 3
row 2
row 2
column 3
column 3
column 3
row 1
row 3

result:

ok Accepted! 28 steps.

Test #3:

score: -100
Runtime Error

input:

4
1101
1000
0011
1010

0110
0011
1010
1010

output:


result: