結果

問題 No.1693 Invasion
ユーザー NanashimaNanashima
提出日時 2021-10-01 23:22:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,234 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 171,796 KB
実行使用メモリ 83,068 KB
最終ジャッジ日時 2023-09-26 22:25:35
合計ジャッジ時間 3,616 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 71 ms
57,820 KB
testcase_10 AC 37 ms
28,640 KB
testcase_11 AC 15 ms
10,920 KB
testcase_12 AC 45 ms
34,204 KB
testcase_13 AC 24 ms
18,628 KB
testcase_14 AC 29 ms
22,160 KB
testcase_15 AC 17 ms
14,436 KB
testcase_16 AC 41 ms
35,844 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 101 ms
83,068 KB
testcase_19 AC 5 ms
5,372 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 93 ms
76,928 KB
testcase_22 AC 89 ms
76,508 KB
testcase_23 AC 96 ms
78,264 KB
権限があれば一括ダウンロードができます

ソースコード

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;

vector<ll> tot;

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 r1,ll r2) {
    return tot[n]*modpow((tot[r1]*tot[r2])%mod,mod-2)%mod;
}

int main() {
    ll 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);
        }

    }
    tot.resize(m+1);
    tot[0]=tot[1]=1;
    for(ll i=2;i<=m;i++) tot[i]=(i*tot[i-1])%mod;
    ll ans=0;
    rep(i,m+1) if(m>=dp[n][i]&&i>=dp[n][i]) {
        ans+=comb(m-dp[n][i],i-dp[n][i],m-i);
        ans%=mod;
    }
    cout << ans << endl;
}
0