結果

問題 No.2159 Filling 4x4 array
ユーザー suisensuisen
提出日時 2022-12-22 23:52:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,979 ms / 5,000 ms
コード長 2,262 bytes
コンパイル時間 1,055 ms
コンパイル使用メモリ 97,556 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 04:03:41
合計ジャッジ時間 81,631 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,245 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1,548 ms
5,376 KB
testcase_03 AC 1,677 ms
5,376 KB
testcase_04 AC 1,121 ms
5,376 KB
testcase_05 AC 1,637 ms
5,376 KB
testcase_06 AC 1,678 ms
5,376 KB
testcase_07 AC 1,645 ms
5,376 KB
testcase_08 AC 1,612 ms
5,376 KB
testcase_09 AC 1,518 ms
5,376 KB
testcase_10 AC 1,699 ms
5,376 KB
testcase_11 AC 1,697 ms
5,376 KB
testcase_12 AC 1,761 ms
5,376 KB
testcase_13 AC 1,778 ms
5,376 KB
testcase_14 AC 1,846 ms
5,376 KB
testcase_15 AC 1,742 ms
5,376 KB
testcase_16 AC 1,689 ms
5,376 KB
testcase_17 AC 1,848 ms
5,376 KB
testcase_18 AC 1,728 ms
5,376 KB
testcase_19 AC 1,616 ms
5,376 KB
testcase_20 AC 1,664 ms
5,376 KB
testcase_21 AC 1,781 ms
5,376 KB
testcase_22 AC 1,749 ms
5,376 KB
testcase_23 AC 1,728 ms
5,376 KB
testcase_24 AC 1,694 ms
5,376 KB
testcase_25 AC 1,918 ms
5,376 KB
testcase_26 AC 1,943 ms
5,376 KB
testcase_27 AC 1,979 ms
5,376 KB
testcase_28 AC 1,956 ms
5,376 KB
testcase_29 AC 1,943 ms
5,376 KB
testcase_30 AC 1,920 ms
5,376 KB
testcase_31 AC 1,860 ms
5,376 KB
testcase_32 AC 1,885 ms
5,376 KB
testcase_33 AC 1,873 ms
5,376 KB
testcase_34 AC 1,957 ms
5,376 KB
testcase_35 AC 1,962 ms
5,376 KB
testcase_36 AC 1,915 ms
5,376 KB
testcase_37 AC 1,888 ms
5,376 KB
testcase_38 AC 1,885 ms
5,376 KB
testcase_39 AC 1,904 ms
5,376 KB
testcase_40 AC 1,869 ms
5,376 KB
testcase_41 AC 1,887 ms
5,376 KB
testcase_42 AC 1,926 ms
5,376 KB
testcase_43 AC 1,923 ms
5,376 KB
testcase_44 AC 1,817 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <array>
#include <iostream>
#include <unordered_map>

#include <atcoder/modint>

using mint = atcoder::modint998244353;

constexpr int L = 30;
constexpr int N = 4;

int main() {
    std::array<int, N> h, w;
    for (auto&& e : h) std::cin >> e, e -= 4;
    for (auto&& e : w) std::cin >> e, e -= 4;

    if (std::accumulate(h.begin(), h.end(), 0LL) != std::accumulate(w.begin(), w.end(), 0LL)) {
        std::cout << 0 << std::endl;
        return 0;
    }

    constexpr int K = 3;

    std::array<uint32_t, 1 << (N - 1) * (N - 1)> add{};
    for (int s = 0; s < 1 << ((N - 1) * (N - 1)); ++s) {
        for (int a = 0; a < N - 1; ++a) for (int b = 0; b < N - 1; ++b) {
            int bit = (s >> (a * (N - 1) + b)) & 1;
            add[s] += bit << a * K;
            add[s] += bit << b * K << N * K;
        }
    }

    std::unordered_map<uint32_t, mint> pd{ { 0, 1 } };
    for (int i = 0; i < L; ++i) {
        uint32_t sub_lo = 0, sub_hi = 0;
        std::array<int, N> hb;
        std::array<int, N> wb;
        for (int a = 0; a < N; ++a) {
            hb[a] = ((h[a] >> i) & 1) << a * K;
            sub_lo += hb[a];
        }
        for (int b = 0; b < N; ++b) {
            wb[b] = ((w[b] >> i) & 1) << b * K;
            sub_hi += wb[b];
        }

        auto split = [](uint32_t s) {
            return std::make_pair(s & ((1 << N * K) - 1), s >> N * K);
        };
        auto merge = [](uint32_t lo, uint32_t hi) {
            return (hi << N * K) | lo;
        };

        std::unordered_map<uint32_t, mint> dp;
        for (const auto& [k, v] : pd) {
            for (uint32_t x : add) {
                auto [lo, hi] = split(k + x);
                for (int b = 0; b < N - 1; ++b) {
                    uint32_t bit = (hi ^ wb[b]) & (1 << b * K);
                    lo += bit << (N - 1 - b) * K;
                    hi += bit;
                }
                for (int a = 0; a < N; ++a) {
                    uint32_t bit = (lo ^ hb[a]) & (1 << a * K);
                    lo += bit;
                    hi += bit << (N - 1 - a) * K;
                }
                dp[merge(lo - sub_lo, hi - sub_hi) >> 1] += v;
            }
        }
        pd.swap(dp);
    }

    std::cout << pd[0].val() << std::endl;

    return 0;
}
0