結果

問題 No.2159 Filling 4x4 array
ユーザー suisensuisen
提出日時 2022-12-22 23:14:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,593 ms / 5,000 ms
コード長 2,214 bytes
コンパイル時間 1,045 ms
コンパイル使用メモリ 95,964 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 04:00:28
合計ジャッジ時間 109,884 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,736 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2,151 ms
5,376 KB
testcase_03 AC 2,284 ms
5,376 KB
testcase_04 AC 1,595 ms
5,376 KB
testcase_05 AC 2,251 ms
5,376 KB
testcase_06 AC 2,335 ms
5,376 KB
testcase_07 AC 2,122 ms
5,376 KB
testcase_08 AC 2,331 ms
5,376 KB
testcase_09 AC 2,234 ms
5,376 KB
testcase_10 AC 2,231 ms
5,376 KB
testcase_11 AC 2,320 ms
5,376 KB
testcase_12 AC 2,340 ms
5,376 KB
testcase_13 AC 2,388 ms
5,376 KB
testcase_14 AC 2,414 ms
5,376 KB
testcase_15 AC 2,297 ms
5,376 KB
testcase_16 AC 2,360 ms
5,376 KB
testcase_17 AC 2,395 ms
5,376 KB
testcase_18 AC 2,255 ms
5,376 KB
testcase_19 AC 2,287 ms
5,376 KB
testcase_20 AC 2,248 ms
5,376 KB
testcase_21 AC 2,430 ms
5,376 KB
testcase_22 AC 2,431 ms
5,376 KB
testcase_23 AC 2,295 ms
5,376 KB
testcase_24 AC 2,266 ms
5,376 KB
testcase_25 AC 2,522 ms
5,376 KB
testcase_26 AC 2,545 ms
5,376 KB
testcase_27 AC 2,556 ms
5,376 KB
testcase_28 AC 2,526 ms
5,376 KB
testcase_29 AC 2,522 ms
5,376 KB
testcase_30 AC 2,593 ms
5,376 KB
testcase_31 AC 2,475 ms
5,376 KB
testcase_32 AC 2,533 ms
5,376 KB
testcase_33 AC 2,523 ms
5,376 KB
testcase_34 AC 2,549 ms
5,376 KB
testcase_35 AC 2,572 ms
5,376 KB
testcase_36 AC 2,552 ms
5,376 KB
testcase_37 AC 2,557 ms
5,376 KB
testcase_38 AC 2,577 ms
5,376 KB
testcase_39 AC 2,497 ms
5,376 KB
testcase_40 AC 2,455 ms
5,376 KB
testcase_41 AC 2,506 ms
5,376 KB
testcase_42 AC 2,489 ms
5,376 KB
testcase_43 AC 2,564 ms
5,376 KB
testcase_44 AC 2,470 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 1 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 = 4;

    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, 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];
        }

        std::unordered_map<uint32_t, mint> dp;
        for (const auto& [k, v] : pd) {
            for (int s = 0; s < 1 << (N - 1) * (N - 1); ++s) {
                uint32_t lo = (k + add[s]) & ((1 << N * K) - 1);
                uint32_t hi = (k + add[s]) >> N * K;

                for (int a = 0; a < N - 1; ++a) {
                    const int b = N - 1;
                    int bit = ((lo ^ hb[a]) >> a * K) & 1;
                    lo += bit << a * K;
                    hi += bit << b * K;
                }
                for (int b = 0; b < N; ++b) {
                    const int a = N - 1;
                    int bit = ((hi ^ wb[b]) >> b * K) & 1;
                    lo += bit << a * K;
                    hi += bit << b * K;
                }
                hi -= sub_hi, lo -= sub_lo;
                dp[((hi << N * K) | lo) >> 1] += v;
            }
        }
        pd.swap(dp);
    }

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

    return 0;
}
0