結果

問題 No.1693 Invasion
ユーザー NanashimaNanashima
提出日時 2021-10-01 23:14:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,336 bytes
コンパイル時間 1,650 ms
コンパイル使用メモリ 172,024 KB
実行使用メモリ 83,148 KB
最終ジャッジ日時 2023-09-26 22:13:17
合計ジャッジ時間 3,919 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 70 ms
57,740 KB
testcase_10 AC 37 ms
28,444 KB
testcase_11 AC 15 ms
11,048 KB
testcase_12 AC 47 ms
34,236 KB
testcase_13 AC 23 ms
18,716 KB
testcase_14 AC 29 ms
22,284 KB
testcase_15 AC 17 ms
14,400 KB
testcase_16 AC 42 ms
35,572 KB
testcase_17 WA -
testcase_18 AC 102 ms
83,148 KB
testcase_19 AC 4 ms
5,384 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 95 ms
76,948 KB
testcase_22 AC 92 ms
76,444 KB
testcase_23 AC 97 ms
78,232 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) {
    if(r1==0) return tot[n]*modpow(tot[r2],mod-2)%mod;
    else if(r2==0) return tot[n]*modpow(tot[r1],mod-2)%mod;
    else 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[1]=1;
    for(ll i=2;i<=m;i++) tot[i]=(i*tot[i-1])%mod;
    ll ans=0;
    rep(i,m+1) if(dp[n][i]!=INF) {
        ans+=comb(m-dp[n][i],i-dp[n][i],m-i);
        ans%=mod;
    }
    cout << ans << endl;
}
0