結果

問題 No.1856 Mex Sum 2
ユーザー pockynypockyny
提出日時 2022-02-26 15:43:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 957 ms / 3,000 ms
コード長 1,245 bytes
コンパイル時間 3,335 ms
コンパイル使用メモリ 139,984 KB
実行使用メモリ 19,544 KB
最終ジャッジ日時 2023-09-17 17:17:33
合計ジャッジ時間 37,967 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
19,288 KB
testcase_01 AC 13 ms
19,232 KB
testcase_02 AC 15 ms
19,252 KB
testcase_03 AC 13 ms
19,452 KB
testcase_04 AC 14 ms
19,252 KB
testcase_05 AC 14 ms
19,196 KB
testcase_06 AC 13 ms
19,316 KB
testcase_07 AC 14 ms
19,212 KB
testcase_08 AC 13 ms
19,184 KB
testcase_09 AC 13 ms
19,184 KB
testcase_10 AC 13 ms
19,196 KB
testcase_11 AC 13 ms
19,204 KB
testcase_12 AC 14 ms
19,188 KB
testcase_13 AC 13 ms
19,232 KB
testcase_14 AC 13 ms
19,184 KB
testcase_15 AC 13 ms
19,400 KB
testcase_16 AC 14 ms
19,192 KB
testcase_17 AC 14 ms
19,208 KB
testcase_18 AC 14 ms
19,408 KB
testcase_19 AC 13 ms
19,244 KB
testcase_20 AC 14 ms
19,408 KB
testcase_21 AC 13 ms
19,200 KB
testcase_22 AC 14 ms
19,192 KB
testcase_23 AC 13 ms
19,236 KB
testcase_24 AC 14 ms
19,220 KB
testcase_25 AC 15 ms
19,252 KB
testcase_26 AC 13 ms
19,212 KB
testcase_27 AC 13 ms
19,228 KB
testcase_28 AC 13 ms
19,188 KB
testcase_29 AC 689 ms
19,352 KB
testcase_30 AC 724 ms
19,304 KB
testcase_31 AC 727 ms
19,256 KB
testcase_32 AC 629 ms
19,248 KB
testcase_33 AC 799 ms
19,380 KB
testcase_34 AC 692 ms
19,288 KB
testcase_35 AC 554 ms
19,240 KB
testcase_36 AC 603 ms
19,280 KB
testcase_37 AC 724 ms
19,252 KB
testcase_38 AC 744 ms
19,252 KB
testcase_39 AC 810 ms
19,284 KB
testcase_40 AC 809 ms
19,368 KB
testcase_41 AC 791 ms
19,272 KB
testcase_42 AC 901 ms
19,256 KB
testcase_43 AC 745 ms
19,376 KB
testcase_44 AC 808 ms
19,316 KB
testcase_45 AC 883 ms
19,328 KB
testcase_46 AC 746 ms
19,264 KB
testcase_47 AC 817 ms
19,292 KB
testcase_48 AC 915 ms
19,304 KB
testcase_49 AC 910 ms
19,376 KB
testcase_50 AC 630 ms
19,292 KB
testcase_51 AC 950 ms
19,384 KB
testcase_52 AC 945 ms
19,376 KB
testcase_53 AC 950 ms
19,360 KB
testcase_54 AC 954 ms
19,376 KB
testcase_55 AC 957 ms
19,332 KB
testcase_56 AC 957 ms
19,488 KB
testcase_57 AC 953 ms
19,400 KB
testcase_58 AC 953 ms
19,252 KB
testcase_59 AC 954 ms
19,328 KB
testcase_60 AC 956 ms
19,468 KB
testcase_61 AC 955 ms
19,256 KB
testcase_62 AC 951 ms
19,284 KB
testcase_63 AC 953 ms
19,268 KB
testcase_64 AC 953 ms
19,384 KB
testcase_65 AC 956 ms
19,524 KB
testcase_66 AC 951 ms
19,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <atcoder/modint>
#include <atcoder/convolution>
#include <vector>

using namespace std;
using namespace atcoder;
using mint = modint998244353;
int mod = 998244353;
mint f[2010][2010],fa[2010],fi[2010];
mint pw(mint a,int x){
    mint ret = 1;
    while(x){
        if(x&1) (ret *= a);
        (a *= a); x /= 2;
    }
    return ret;
}

mint nck(int n,int k){
    if(n<0 || k<0 || n<k) return 0;
    return fa[n]*fi[k]*fi[n - k];
}

void solve(){
    int MX = 2010;
    fi[0] = fa[0] = 1;
    for(int i=1;i<MX;i++) fa[i] = fa[i - 1]*i;
    fi[MX - 1] = (mint)1/fa[MX - 1];
    for(int i=MX - 2;i>=1;i--) fi[i] = fi[i + 1]*(i + 1);
}

int main(){
    int i,j,k,x,n,m; cin >> n >> m;
    solve();
    for(k=0;k<=n;k++){
        vector<mint> g(n + 2),h(n + 2);
        for(j=0;j<=n + 1;j++) g[j] = pw(m + 1 - j,k)*pw(mod - 1,j)*fi[j];
        for(j=0;j<=n + 1;j++) h[j] = fi[j];
        g = convolution(g,h);
        for(j=0;j<=min(m + 1,n + 1);j++) f[k][j] = pw(m + 1,n - k)*fa[j]*g[j];
    }
    mint ans = 0;
    for(i=1;i<=n + 1;i++){
        for(k=1;k<=n;k++) ans += nck(n,k)*f[k][i];
    }
    cout << ans.val() << endl;
}
0