結果

問題 No.2633 Subsequence Combination Score
ユーザー noya2noya2
提出日時 2024-02-12 01:17:40
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 1,856 bytes
コンパイル時間 4,947 ms
コンパイル使用メモリ 315,336 KB
実行使用メモリ 16,320 KB
最終ジャッジ日時 2024-02-16 20:51:34
合計ジャッジ時間 12,578 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
16,320 KB
testcase_01 AC 138 ms
16,320 KB
testcase_02 AC 139 ms
16,320 KB
testcase_03 AC 138 ms
16,320 KB
testcase_04 AC 140 ms
16,320 KB
testcase_05 AC 141 ms
16,320 KB
testcase_06 AC 139 ms
16,320 KB
testcase_07 AC 141 ms
16,320 KB
testcase_08 AC 149 ms
16,320 KB
testcase_09 AC 145 ms
16,320 KB
testcase_10 AC 145 ms
16,320 KB
testcase_11 AC 149 ms
16,320 KB
testcase_12 AC 149 ms
16,320 KB
testcase_13 AC 146 ms
16,320 KB
testcase_14 AC 147 ms
16,320 KB
testcase_15 AC 149 ms
16,320 KB
testcase_16 AC 149 ms
16,320 KB
testcase_17 AC 158 ms
16,320 KB
testcase_18 AC 150 ms
16,320 KB
testcase_19 AC 151 ms
16,320 KB
testcase_20 AC 151 ms
16,320 KB
testcase_21 AC 154 ms
16,320 KB
testcase_22 AC 148 ms
16,320 KB
testcase_23 AC 148 ms
16,320 KB
testcase_24 AC 150 ms
16,320 KB
testcase_25 AC 146 ms
16,320 KB
testcase_26 AC 150 ms
16,320 KB
testcase_27 AC 148 ms
16,320 KB
testcase_28 AC 148 ms
16,320 KB
testcase_29 AC 142 ms
16,320 KB
testcase_30 AC 150 ms
16,320 KB
testcase_31 AC 141 ms
16,320 KB
testcase_32 AC 143 ms
16,320 KB
testcase_33 AC 154 ms
16,320 KB
testcase_34 AC 150 ms
16,320 KB
testcase_35 AC 151 ms
16,320 KB
testcase_36 AC 152 ms
16,320 KB
testcase_37 AC 147 ms
16,320 KB
testcase_38 AC 157 ms
16,320 KB
testcase_39 AC 149 ms
16,320 KB
testcase_40 AC 149 ms
16,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using mint = atcoder::modint998244353;

const int bx = 19;
const int mx = 1<<bx;
int cnt[mx];
mint dp[mx], fact[mx], ifact[mx], pow2[mx];

void table_build(){
    fact[0] = 1;
    for (int i = 1; i < mx; i++){
        fact[i] = fact[i-1] * i;
    }
    ifact[mx-1] = fact[mx-1].inv();
    for (int i = mx-2; i >= 0; i--){
        ifact[i] = ifact[i+1] * (i+1);
    }
    pow2[0] = 1;
    for (int i = 1; i < mx; i++){
        pow2[i] = pow2[i-1] * 2;
    }
}

array<vector<mint>,bx> fs, ex;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    while (n--){
        int x; cin >> x;
        cnt[x]++;
    }
    table_build();
    for (int d = 1; d < bx; d++){
        fs[d].resize(1<<d);
        ex[d].resize(1<<d);
        for (int i = 0; i < (1<<(d-1)); i++){
            ex[d][i] = ifact[i];
        }
        atcoder::internal::butterfly(ex[d]);
    }
    dp[0] = pow2[cnt[0]];
    auto dfs = [&](auto sfs, int l, int r, int k) -> void {
        if (r - l <= 1) return ;
        int m = (l + r) / 2;
        sfs(sfs,l,m,k-1);
        fill(fs[k+1].begin(),fs[k+1].end(),0);
        for (int i = l; i < m; i++){
            fs[k+1][i-l] = dp[i];
        }
        atcoder::internal::butterfly(fs[k+1]);
        for (int i = 0; i < (1<<(k+1)); i++){
            fs[k+1][i] *= ex[k+1][i];
        }
        atcoder::internal::butterfly_inv(fs[k+1]);
        mint iv = ifact[1<<(k+1)] * fact[(1<<(k+1))-1];
        for (auto &x : fs[k+1]) x *= iv;
        for (int i = (1<<(k-1)); i < (1<<k); i++){
            dp[l+i] += fs[k+1][i] * (pow2[cnt[l+i]]-1);
        }
        sfs(sfs,m,r,k-1);
    };
    dfs(dfs,0,1<<17,17);
    mint ans = -1;
    for (int i = 0; i < mx; i++){
        ans += dp[i] * fact[i];
    }
    cout << ans.val() << endl;
}
0