結果

問題 No.1856 Mex Sum 2
ユーザー ぷらぷら
提出日時 2022-02-25 22:20:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,681 bytes
コンパイル時間 2,096 ms
コンパイル使用メモリ 201,232 KB
実行使用メモリ 39,964 KB
最終ジャッジ日時 2023-09-16 17:23:13
合計ジャッジ時間 20,197 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
9,324 KB
testcase_01 AC 6 ms
9,344 KB
testcase_02 AC 7 ms
9,820 KB
testcase_03 AC 6 ms
9,340 KB
testcase_04 AC 7 ms
9,684 KB
testcase_05 AC 6 ms
9,748 KB
testcase_06 AC 6 ms
9,632 KB
testcase_07 AC 6 ms
9,476 KB
testcase_08 AC 6 ms
9,336 KB
testcase_09 AC 6 ms
9,400 KB
testcase_10 AC 6 ms
9,372 KB
testcase_11 AC 6 ms
9,444 KB
testcase_12 AC 6 ms
9,536 KB
testcase_13 AC 6 ms
9,280 KB
testcase_14 AC 6 ms
9,340 KB
testcase_15 AC 6 ms
9,300 KB
testcase_16 AC 6 ms
9,440 KB
testcase_17 AC 7 ms
9,692 KB
testcase_18 AC 7 ms
9,636 KB
testcase_19 AC 6 ms
9,384 KB
testcase_20 AC 6 ms
9,368 KB
testcase_21 AC 6 ms
9,316 KB
testcase_22 AC 7 ms
9,652 KB
testcase_23 AC 6 ms
9,380 KB
testcase_24 AC 7 ms
9,872 KB
testcase_25 AC 7 ms
9,632 KB
testcase_26 AC 6 ms
9,336 KB
testcase_27 AC 6 ms
9,404 KB
testcase_28 AC 6 ms
9,308 KB
testcase_29 AC 206 ms
37,140 KB
testcase_30 AC 211 ms
38,412 KB
testcase_31 AC 217 ms
38,200 KB
testcase_32 AC 200 ms
35,200 KB
testcase_33 AC 259 ms
39,460 KB
testcase_34 AC 206 ms
37,288 KB
testcase_35 AC 155 ms
34,088 KB
testcase_36 AC 170 ms
35,412 KB
testcase_37 AC 216 ms
38,188 KB
testcase_38 AC 219 ms
39,160 KB
testcase_39 AC 243 ms
39,624 KB
testcase_40 AC 242 ms
39,644 KB
testcase_41 AC 237 ms
39,188 KB
testcase_42 AC 518 ms
39,964 KB
testcase_43 AC 413 ms
36,556 KB
testcase_44 AC 460 ms
37,928 KB
testcase_45 AC 507 ms
39,528 KB
testcase_46 AC 417 ms
36,912 KB
testcase_47 AC 463 ms
38,312 KB
testcase_48 AC 527 ms
38,892 KB
testcase_49 AC 523 ms
38,764 KB
testcase_50 AC 341 ms
33,960 KB
testcase_51 AC 552 ms
39,572 KB
testcase_52 AC 547 ms
39,464 KB
testcase_53 AC 553 ms
39,752 KB
testcase_54 AC 553 ms
39,636 KB
testcase_55 AC 553 ms
39,844 KB
testcase_56 AC 553 ms
39,620 KB
testcase_57 AC 555 ms
39,760 KB
testcase_58 AC 552 ms
39,816 KB
testcase_59 AC 554 ms
39,776 KB
testcase_60 AC 553 ms
39,632 KB
testcase_61 AC 554 ms
39,616 KB
testcase_62 AC 553 ms
39,752 KB
testcase_63 AC 553 ms
39,620 KB
testcase_64 AC 553 ms
39,644 KB
testcase_65 AC 553 ms
39,684 KB
testcase_66 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

long long fac[200005], finv[200005], inv[200005];

void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < 200005; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}

long long dp[2022][2022],fac1[2022];

int main() {
    int N,M;
    cin >> N >> M;
    dp[0][0] = 1;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            dp[i+1][j] += dp[i][j]*j%mod;
            dp[i+1][j] %= mod;
            dp[i+1][j+1] += dp[i][j];
            dp[i+1][j+1] %= mod;
        }
    }
    COMinit();
    for(int i = 1; i < N; i++) {
        for(int j = 0; j < N; j++) {
            dp[N][j] += dp[i][j]*modpow(M+1,N-i)%mod*COM(N,i)%mod;
            dp[N][j] %= mod;
        }
    }
    long long sum = 0;
    fac1[0] = 1;
    for(int i = 1; i <= N; i++) {
        fac1[i] = fac1[i-1]*(M-i+2)%mod;
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= min(M+1,N); j++) {
            if(i <= j) {
                sum += dp[N][j]*COM(j,i)%mod*fac[i]%mod*fac1[j]%mod*modpow(fac1[i],mod-2)%mod;
                sum %= mod;
            }
        }
    }
    cout << sum << endl;
}
0