結果

問題 No.1693 Invasion
ユーザー NanashimaNanashima
提出日時 2021-10-01 22:11:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,170 bytes
コンパイル時間 1,858 ms
コンパイル使用メモリ 170,536 KB
実行使用メモリ 62,352 KB
最終ジャッジ日時 2023-09-26 17:32:55
合計ジャッジ時間 5,819 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
#define all(a)  (a).begin(),(a).end()
#define rall(a)  (a).rbegin(),(a).rend()
typedef long long ll;
typedef pair<ll,ll> pl;

const ll mod=998244353;

ll modpow(ll n,ll r) {
    ll num=1;
    while(r) {
        if(r&1) num=num*n%mod;
        n=n*n%mod;
        r/=2;
    }
    return num;
}

ll comb(ll n,ll r) {
    ll x=1,y=1;
    for(ll i=0;i<r;i++) x=x*(n-i)%mod;
    for(ll i=1;i<=r;i++) y=y*i%mod;
    return x*modpow(y,mod-2)%mod;
}

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<vector<ll>> dp(n+1,vector<ll> (m+1,INF));
    dp[0][0]=0;
    rep(i,n) for(int j=0;j<=m;j++) {
        if(dp[i][j]!=INF) dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
        if(j-a[i]>=0) {
            if(dp[i][j-a[i]]!=INF) {
                dp[i][j]=min(dp[i][j-a[i]]+1,dp[i][j]);
            }
            dp[i+1][j]=min(dp[i+1][j],dp[i][j-a[i]]+1);
        }

    }
    ll ans=0;
    rep(i,m+1) if(dp[n][i]!=INF) {
        ans+=comb(m-dp[n][i],i-dp[n][i]);
        ans%=mod;
    }
    cout << ans << endl;
}
0