結果

問題 No.1693 Invasion
ユーザー ぷらぷら
提出日時 2021-10-01 21:29:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,131 bytes
コンパイル時間 2,115 ms
コンパイル使用メモリ 200,368 KB
実行使用メモリ 9,064 KB
最終ジャッジ日時 2023-09-26 16:27:22
合計ジャッジ時間 3,314 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,084 KB
testcase_01 AC 6 ms
8,104 KB
testcase_02 AC 6 ms
8,036 KB
testcase_03 AC 7 ms
8,032 KB
testcase_04 AC 6 ms
8,036 KB
testcase_05 AC 6 ms
8,080 KB
testcase_06 AC 6 ms
8,148 KB
testcase_07 AC 6 ms
8,036 KB
testcase_08 AC 6 ms
8,040 KB
testcase_09 AC 15 ms
8,600 KB
testcase_10 AC 10 ms
9,064 KB
testcase_11 AC 8 ms
8,556 KB
testcase_12 AC 12 ms
8,988 KB
testcase_13 AC 9 ms
8,588 KB
testcase_14 AC 10 ms
8,352 KB
testcase_15 AC 8 ms
8,312 KB
testcase_16 AC 11 ms
8,552 KB
testcase_17 AC 6 ms
8,096 KB
testcase_18 AC 19 ms
8,816 KB
testcase_19 AC 7 ms
8,872 KB
testcase_20 AC 6 ms
8,288 KB
testcase_21 AC 19 ms
8,844 KB
testcase_22 AC 18 ms
8,832 KB
testcase_23 AC 18 ms
8,800 KB
権限があれば一括ダウンロードができます

ソースコード

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 dp[100005];
int inf = 1001001001;

int main() {
    int N,M;
    cin >> N >> M;
    vector<int>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(int i = 0; i <= M; i++) {
        dp[i] = inf;
    }
    dp[0] = 0;
    for(int i = 0; i <= M; i++) {
        for(int j = 0; j < N; j++) {
            if(i+A[j] <= M) {
                dp[i+A[j]] = min(dp[i+A[j]],dp[i]+1);
            }
        }
    }
    long long ans = 0;
    COMinit();
    for(int i = 0; i <= M; i++) {
        ans += COM(M-dp[i],i-dp[i]);
        ans %= mod;
    }
    cout << ans << endl;
}
0