結果

問題 No.1693 Invasion
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-07 00:07:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,370 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 111,744 KB
実行使用メモリ 98,552 KB
最終ジャッジ日時 2023-08-28 10:51:44
合計ジャッジ時間 3,311 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
18,420 KB
testcase_01 AC 18 ms
18,388 KB
testcase_02 AC 17 ms
18,668 KB
testcase_03 AC 17 ms
18,760 KB
testcase_04 AC 17 ms
18,720 KB
testcase_05 AC 18 ms
18,588 KB
testcase_06 AC 16 ms
18,748 KB
testcase_07 AC 16 ms
18,672 KB
testcase_08 AC 16 ms
18,820 KB
testcase_09 AC 70 ms
73,348 KB
testcase_10 AC 43 ms
44,124 KB
testcase_11 AC 24 ms
26,640 KB
testcase_12 AC 48 ms
49,888 KB
testcase_13 AC 33 ms
34,384 KB
testcase_14 AC 37 ms
37,724 KB
testcase_15 AC 29 ms
30,140 KB
testcase_16 AC 49 ms
51,264 KB
testcase_17 AC 17 ms
18,720 KB
testcase_18 AC 97 ms
98,552 KB
testcase_19 AC 20 ms
20,832 KB
testcase_20 AC 16 ms
18,480 KB
testcase_21 AC 88 ms
92,708 KB
testcase_22 AC 89 ms
91,860 KB
testcase_23 AC 93 ms
93,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>

using namespace std;

using ll = long long;
const ll modc=998244353, MAX=1000000;
vector<ll> f, finv;

ll inv(ll x){
    ll ans = 1, e = modc-2;
    x %= modc;

    while (e > 0){
        if ((e & 1LL)) ans = (ans * x) % modc;
        e = e >> 1LL;
        x = (x*x) % modc;
    }

    return ans;
}

void init(){
    f.resize(MAX+1); finv.resize(MAX+1);
    f[0] = 1;
    for (int i=1; i<=MAX; i++) f[i] = (f[i-1]*i) % modc;
    finv[MAX] = inv(f[MAX]);
    for (int i=MAX-1; i>=0; i--) finv[i] = (finv[i+1] * (i+1)) % modc;
}

ll C(ll n, ll k){ 
    if (n < k || k < 0) return 0;

    return (((f[n] * finv[k]) % modc) * finv[n-k]) % modc;
}

int main(){

    init();
    ll N, M, ans=0;
    cin >> N >> M;
    vector<ll> A(N);
    for (int i=0; i<N; i++) cin >> A[i];
    vector<vector<ll>> dp(N+1, vector<ll>(M+1, 1e18));
    dp[0][0] = 0;
    for (int i=1; i<=N; i++){
        for (int j=0; j<=M; j++){
            dp[i][j] = min(dp[i][j], dp[i-1][j]);
            if (j-A[i-1]>=0) dp[i][j] = min(dp[i][j], dp[i][j-A[i-1]]+1);
        }
    }

    for (int i=0; i<=M; i++){
        ans += C(M-dp[N][i], i-dp[N][i]);
        ans %= modc;
    }

    cout << ans << endl;

    return 0;
}
0