結果

問題 No.2159 Filling 4x4 array
ユーザー suisensuisen
提出日時 2022-12-22 22:04:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,102 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 91,404 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2024-04-29 03:52:00
合計ジャッジ時間 7,785 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 TLE -
testcase_05 AC 5 ms
6,948 KB
testcase_06 AC 12 ms
6,948 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 17 ms
6,944 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 5 ms
6,944 KB
testcase_11 AC 8 ms
6,944 KB
testcase_12 AC 5 ms
6,944 KB
testcase_13 AC 13 ms
6,944 KB
testcase_14 AC 20 ms
6,940 KB
testcase_15 AC 9 ms
6,944 KB
testcase_16 AC 6 ms
6,944 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 6 ms
6,944 KB
testcase_19 AC 10 ms
6,944 KB
testcase_20 AC 3 ms
6,944 KB
testcase_21 AC 28 ms
6,940 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 12 ms
6,940 KB
testcase_24 AC 8 ms
6,944 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <array>
#include <iostream>
#include <map>

#include <atcoder/modint>

using mint = atcoder::modint998244353;

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

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

    using key = std::pair<std::array<int, N>, std::array<int, N>>;
    std::array<std::map<key, mint>, L + 1> dp{};
    dp[0][{ r, c }] = 1;
    for (int i = 0; i < L; ++i) {
        for (const auto& [k, v] : dp[i]) {
            for (int s = 0; s < 1 << ((N - 1) * (N - 1)); ++s) {
                auto [r, c] = k;
                std::array<std::array<int, N>, N> d;
                for (int a = 0; a < N - 1; ++a) {
                    for (int b = 0; b < N - 1; ++b) {
                        int bit = (s >> (a * (N - 1) + b)) & 1;
                        d[a][b] = bit;
                        r[a] -= bit, c[b] -= bit;
                    }
                }
                for (int a = 0; a < N - 1; ++a) {
                    const int b = N - 1;
                    int bit = r[a] & 1;
                    d[a][b] = bit;
                    r[a] -= bit, c[b] -= bit;
                }
                for (int b = 0; b < N - 1; ++b) {
                    const int a = N - 1;
                    int bit = c[b] & 1;
                    d[a][b] = bit;
                    r[a] -= bit, c[b] -= bit;
                }
                {
                    int bit = r[N - 1] & 1;
                    d[N - 1][N - 1] = bit;
                    r[N - 1] -= bit, c[N - 1] -= bit;
                }
                bool ok = (c[N - 1] & 1) == 0;
                for (int a = 0; a < N; ++a) {
                    ok &= r[a] >= 0;
                    r[a] >>= 1;
                }
                for (int b = 0; b < N; ++b) {
                    ok &= c[b] >= 0;
                    c[b] >>= 1;
                }
                if (ok) {
                    dp[i + 1][{ r, c }] += v;
                }
            }
        }
    }

    std::cout << dp[L][key{}].val() << std::endl;

    return 0;
}
0