結果

問題 No.2633 Subsequence Combination Score
ユーザー noya2noya2
提出日時 2024-02-12 00:17:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,843 bytes
コンパイル時間 5,307 ms
コンパイル使用メモリ 315,188 KB
実行使用メモリ 14,264 KB
最終ジャッジ日時 2024-02-16 20:51:03
合計ジャッジ時間 13,118 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
14,264 KB
testcase_01 AC 143 ms
14,264 KB
testcase_02 AC 144 ms
14,264 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 145 ms
14,264 KB
testcase_31 AC 145 ms
14,264 KB
testcase_32 AC 145 ms
14,264 KB
testcase_33 AC 153 ms
14,264 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

void factrial_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);
    }
}

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;
        exist[x] = true;
    }
    exist[0] = true;
    factrial_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] = 1;
    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++){
            if (exist[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];
        }
        sfs(sfs,m,r,k-1);
    };
    dfs(dfs,0,1<<17,17);
    mint ans = -1;
    for (int i = 0; i < mx; i++){
        if (exist[i]){
            ans += dp[i] * fact[i];
        }
    }
    cout << ans.val() << endl;
}
0