結果

問題 No.2663 Zero-Sum Submatrices
ユーザー chirprushchirprush
提出日時 2024-04-02 02:45:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 2,660 bytes
コンパイル時間 1,038 ms
コンパイル使用メモリ 80,116 KB
実行使用メモリ 36,456 KB
最終ジャッジ日時 2024-04-02 02:45:35
合計ジャッジ時間 3,618 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 3 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 3 ms
6,676 KB
testcase_22 AC 3 ms
7,784 KB
testcase_23 AC 4 ms
7,784 KB
testcase_24 AC 4 ms
7,784 KB
testcase_25 AC 10 ms
11,880 KB
testcase_26 AC 5 ms
11,880 KB
testcase_27 AC 5 ms
11,880 KB
testcase_28 AC 7 ms
20,072 KB
testcase_29 AC 7 ms
20,072 KB
testcase_30 AC 12 ms
36,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>

typedef long long ll;

template<typename T>
void read_some(std::vector<T> &v, int N) {
    for (int i = 0; i < N; i++) {
        T a;
        std::cin >> a;
        v.push_back(a);
    }
}

int a[(1 << 12)][(1 << 12)] = {0};

void construct_line(int i, int j, int n, bool horizontal) {
    for (int v = 0; v < (1 << (n + 1)); v++) {
        int place = v % 2 + 2 * (v / 4);
        int side = (v / 2) % 2;

        if (horizontal) {
            a[i + side][j + place] = v;
        } else {
            a[i + place][j + side] = v;
        }
    }
}

void add(int i, int j, int n, int m, int value) {
    // std::cout << "add(" << i << ", " << j << ", "  << n << ", " << m << ", " << value << ")" << std::endl;
    for (int k = 0; k < (1 << n); k++) {
        for (int l = 0; l < (1 << m); l++) {
            a[i + k][j + l] += value;
        }
    }
}

void construct(int i, int j, int n, int m) {
    // std::cout << "construct(" << i << ", " << j << ", "  << n << ", " << m << ")" << std::endl;
    if (n == 1) {
        construct_line(i, j, m, true);
    } else if (m == 1) {
        construct_line(i, j, n, false);
    } else {
        construct(i, j, n - 1, m - 1);

        construct(i, j + (1 << (m - 1)), n - 1, m - 1);
        add(i, j + (1 << (m - 1)), n - 1, m - 1, 1 << (m + n - 2));

        construct(i + (1 << (n - 1)), j, n - 1, m - 1);
        add(i + (1 << (n - 1)), j, n - 1, m - 1, 1 << (m + n - 1));

        construct(i + (1 << (n - 1)), j + (1 << (m - 1)), n - 1, m - 1);
        add(i + (1 << (n - 1)), j + (1 << (m - 1)), n - 1, m - 1, (1 << (m + n - 1)) + (1 << (m + n - 2)));
    }
}

int main() {
    int n, m;
    std::cin >> n >> m;

    construct(0, 0, n, m);

    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < (1 << m); j++) {
            std::cout << a[i][j] << " ";
        }

        std::cout << std::endl;
    }

    /*
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < (1 << m); j++) {
            for (int k = i + 1; k < (1 << n); k++) {
                for (int l = j + 1; l < (1 << m); l++) {
                    if (a[i][j] ^ a[i][l] ^ a[k][j] ^ a[k][l]) {
                        std::cout << "Bad pair" << std::endl;
                        std::cout << i << " " << j << " " << k << " " << l << std::endl;
                        std::cout << a[i][j] << " " << a[i][l] << " " << a[k][j] << " " << a[k][l] << std::endl;
                        goto end;
                    }
                }
            }
        }
    }

end:;
    */

    return 0;
}
0