結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
10,176 KB
testcase_01 AC 112 ms
10,176 KB
testcase_02 AC 113 ms
10,176 KB
testcase_03 AC 121 ms
10,432 KB
testcase_04 AC 114 ms
10,432 KB
testcase_05 AC 113 ms
10,432 KB
testcase_06 AC 117 ms
10,432 KB
testcase_07 AC 119 ms
10,432 KB
testcase_08 AC 127 ms
10,176 KB
testcase_09 AC 128 ms
10,432 KB
testcase_10 AC 127 ms
10,432 KB
testcase_11 AC 128 ms
10,432 KB
testcase_12 AC 127 ms
10,432 KB
testcase_13 AC 129 ms
10,432 KB
testcase_14 AC 129 ms
10,432 KB
testcase_15 AC 130 ms
10,432 KB
testcase_16 AC 129 ms
10,432 KB
testcase_17 AC 127 ms
10,432 KB
testcase_18 AC 128 ms
10,432 KB
testcase_19 AC 129 ms
10,432 KB
testcase_20 AC 128 ms
10,432 KB
testcase_21 AC 130 ms
10,432 KB
testcase_22 AC 130 ms
10,432 KB
testcase_23 AC 124 ms
10,432 KB
testcase_24 AC 122 ms
10,432 KB
testcase_25 AC 124 ms
10,432 KB
testcase_26 AC 128 ms
10,432 KB
testcase_27 AC 129 ms
10,432 KB
testcase_28 AC 129 ms
10,432 KB
testcase_29 AC 117 ms
10,176 KB
testcase_30 AC 113 ms
10,176 KB
testcase_31 AC 116 ms
10,176 KB
testcase_32 AC 111 ms
10,176 KB
testcase_33 AC 123 ms
10,432 KB
testcase_34 AC 123 ms
10,432 KB
testcase_35 AC 126 ms
10,432 KB
testcase_36 AC 119 ms
10,432 KB
testcase_37 AC 118 ms
10,432 KB
testcase_38 AC 129 ms
10,432 KB
testcase_39 AC 123 ms
10,432 KB
testcase_40 AC 120 ms
10,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int mx = 1<<17;
int cnt[mx];
mint dp[mx], fact[mx], ifact[mx], pow2[mx], ipow2[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] = ipow2[0] = 1;
    mint i2 = mint(2).inv();
    for (int i = 1; i < mx; i++){
        pow2[i] = pow2[i-1] * 2;
        ipow2[i] = ipow2[i-1] * i2;
    }
}

array<vector<mint>,19> 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 < 19; 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]);
    }
    mint ans = 0;
    auto dfs = [&](auto sfs, int l, int r, int k) -> void {
        if (r - l == 1){
            dp[l] += ifact[l];
            dp[l] *= pow2[cnt[l]]-1;
            ans += dp[l] * fact[l];
            return ;
        }
        int m = (l + r) / 2;
        sfs(sfs,l,m,k-1);
        if (k <= 5){
            for (int i = l; i < m; i++) for (int j = m; j < r; j++){
                dp[j] += dp[i] * ifact[j-i];
            }
        }
        else {
            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]);
            for (int i = (1<<(k-1)); i < (1<<k); i++){
                dp[l+i] += fs[k+1][i] * ipow2[k+1];
            }
        }
        sfs(sfs,m,r,k-1);
    };
    dfs(dfs,0,1<<17,17);
    cout << ans.val() << endl;
}
0