結果

問題 No.2159 Filling 4x4 array
ユーザー 👑 NachiaNachia
提出日時 2022-12-07 08:54:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 829 ms / 5,000 ms
コード長 4,389 bytes
コンパイル時間 1,637 ms
コンパイル使用メモリ 103,664 KB
実行使用メモリ 35,172 KB
最終ジャッジ日時 2024-04-22 23:10:34
合計ジャッジ時間 39,682 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 795 ms
35,040 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 800 ms
35,172 KB
testcase_03 AC 803 ms
35,100 KB
testcase_04 AC 806 ms
35,036 KB
testcase_05 AC 808 ms
34,968 KB
testcase_06 AC 800 ms
35,168 KB
testcase_07 AC 799 ms
35,040 KB
testcase_08 AC 793 ms
35,044 KB
testcase_09 AC 795 ms
35,168 KB
testcase_10 AC 804 ms
35,168 KB
testcase_11 AC 800 ms
35,040 KB
testcase_12 AC 810 ms
35,120 KB
testcase_13 AC 798 ms
35,168 KB
testcase_14 AC 792 ms
35,164 KB
testcase_15 AC 799 ms
35,040 KB
testcase_16 AC 811 ms
35,040 KB
testcase_17 AC 804 ms
35,096 KB
testcase_18 AC 792 ms
35,044 KB
testcase_19 AC 790 ms
35,036 KB
testcase_20 AC 793 ms
34,992 KB
testcase_21 AC 796 ms
35,164 KB
testcase_22 AC 814 ms
35,168 KB
testcase_23 AC 820 ms
34,988 KB
testcase_24 AC 829 ms
35,040 KB
testcase_25 AC 823 ms
35,164 KB
testcase_26 AC 820 ms
35,172 KB
testcase_27 AC 824 ms
35,168 KB
testcase_28 AC 817 ms
35,168 KB
testcase_29 AC 808 ms
35,000 KB
testcase_30 AC 810 ms
34,988 KB
testcase_31 AC 797 ms
35,008 KB
testcase_32 AC 807 ms
34,980 KB
testcase_33 AC 806 ms
35,168 KB
testcase_34 AC 817 ms
35,148 KB
testcase_35 AC 809 ms
35,036 KB
testcase_36 AC 817 ms
35,036 KB
testcase_37 AC 814 ms
35,044 KB
testcase_38 AC 800 ms
35,040 KB
testcase_39 AC 808 ms
35,044 KB
testcase_40 AC 807 ms
35,172 KB
testcase_41 AC 805 ms
35,124 KB
testcase_42 AC 818 ms
35,048 KB
testcase_43 AC 806 ms
35,008 KB
testcase_44 AC 810 ms
35,056 KB
testcase_45 AC 2 ms
6,940 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
using Modint = atcoder::static_modint<998244353>;

constexpr const int STATE_NUM = 7*7*7*7*7*7*7*7;

vector<vector<int>> OPERATORS = {
    { 0, 0, 4 },
    { 0, 1, 4 },
    { 0, 2, 4 },
    { 0, 3, 4 },
    { 1, 4 },
    { 0, 0, 5 },
    { 0, 1, 5 },
    { 0, 2, 5 },
    { 0, 3, 5 },
    { 1, 5 },
    { 0, 0, 6 },
    { 0, 0, 7 },
    { 1, 0 },
    { 0, 1, 6 },
    { 0, 1, 7 },
    { 1, 1 },
    { 0, 2, 6 },
    { 0, 2, 7 },
    { 1, 2 },
    { 0, 3, 6 },
    { 1, 6 },
    { 0, 3, 7 },
    { 1, 3 },
    { 1, 7 }
};

vector<unsigned int> TABLE_SIZE;
vector<unsigned int> TABLE_DELTA;
vector<vector<unsigned int>> TABLE_TO;

unsigned int TABLE_IDX(const vector<unsigned int>& z, const vector<unsigned int>& a){
    unsigned int i = 0;
    for(int j=(int)z.size()-1; j>=0; j--) i = i * z[j] + a[j];
    return i;
}

unsigned int CALC_TABLE_SIZE(const vector<unsigned int>& z){
    unsigned int i = 1;
    for(int j=(int)z.size()-1; j>=0; j--) i = i * z[j];
    return i;
}

void PRECALC(){
    vector<unsigned int> WIDTH = { 4,4,4,4, 4,4,4,4 };
    TABLE_SIZE.push_back(CALC_TABLE_SIZE(WIDTH));
    for(auto op : OPERATORS){
        vector<unsigned int> WIDTH_NEW = WIDTH;
        vector<unsigned int> to;
        unsigned int tableSize = 0;
        unsigned int tableDelta = 0;
        if(op[0] == 0){
            to.resize(TABLE_SIZE.back());
            for(size_t i=1; i<op.size(); i++) WIDTH_NEW[op[i]]++;
            vector<unsigned int> ptmp(8, 0);
            for(size_t i=1; i<op.size(); i++) ptmp[op[i]]++;
            tableDelta = TABLE_IDX(WIDTH_NEW, ptmp);
            tableSize = CALC_TABLE_SIZE(WIDTH_NEW);
            auto dfs = [WIDTH, WIDTH_NEW, &ptmp, &to](auto& dfs, int d) -> void {
                if(d == 8){
                    to[TABLE_IDX(WIDTH, ptmp)] = TABLE_IDX(WIDTH_NEW, ptmp);
                }
                else{
                    for(ptmp[d] = 0; ptmp[d] < WIDTH[d]; ptmp[d]++) dfs(dfs, d+1);
                }
            };
            dfs(dfs, 0);
        }
        else{
            for(size_t i=1; i<op.size(); i++) WIDTH_NEW[op[i]] /= 2;
            vector<unsigned int> ptmp(8, 0);
            for(size_t i=1; i<op.size(); i++) ptmp[op[i]]++;
            tableDelta = TABLE_IDX(WIDTH_NEW, ptmp);
            tableSize = CALC_TABLE_SIZE(WIDTH_NEW);
            to.resize(tableSize);
            auto dfs = [WIDTH, WIDTH_NEW, op, &ptmp, &to](auto& dfs, int d) -> void {
                if(d == 8){
                    vector<unsigned int> tmp2 = ptmp;
                    for(size_t i=1; i<op.size(); i++) tmp2[op[i]] *= 2;
                    to[TABLE_IDX(WIDTH_NEW, ptmp)] = TABLE_IDX(WIDTH, tmp2);
                }
                else{
                    for(ptmp[d] = 0; ptmp[d] < WIDTH_NEW[d]; ptmp[d]++) dfs(dfs, d+1);
                }
            };
            dfs(dfs, 0);
        }
        TABLE_SIZE.push_back(tableSize);
        TABLE_DELTA.push_back(tableDelta);
        TABLE_TO.push_back(move(to));
        WIDTH = WIDTH_NEW;
    }
}

int main(){
    vector<unsigned long long> A(8);
    rep(i,8) cin >> A[i];
    if(A[0] + A[1] + A[2] + A[3] != A[4] + A[5] + A[6] + A[7]){ cout << "0\n"; return 0; }
    rep(i,8) if(A[i] < 4){ cout << "0\n"; return 0; }
    rep(i,8) A[i] -= 4;

    PRECALC();

    vector<Modint> dp(TABLE_SIZE[0]);
    dp[0] = 1;

    for(int d=0; d<30; d++){
        for(size_t opuct=0; opuct<OPERATORS.size(); opuct++){
            auto op = OPERATORS[opuct];
            unsigned int tableSize = TABLE_SIZE[opuct+1];
            unsigned int tableDelta = TABLE_DELTA[opuct];
            unsigned int* tableTo = TABLE_TO[opuct].data();
            vector<Modint> tmp(tableSize);
            if(op[0] == 0){
                for(unsigned int i=0; i<dp.size(); i++) tmp[tableTo[i]] = dp[i];
                for(unsigned int i=0; i<dp.size(); i++) tmp[tableTo[i] + tableDelta] += dp[i];
            }
            if(op[0] == 1){
                if((A[op[1]]>>d)&1) for(unsigned int i=0; i<tmp.size(); i++) tmp[i] = dp[tableTo[i] + tableDelta];
                else                for(unsigned int i=0; i<tmp.size(); i++) tmp[i] = dp[tableTo[i]];
            }
            swap(dp, tmp);
        }
    }

    cout << dp[0].val() << '\n';
    return 0;
}
0