結果

問題 No.1693 Invasion
ユーザー yakkiyakki
提出日時 2021-10-01 21:47:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 2,003 bytes
コンパイル時間 1,157 ms
コンパイル使用メモリ 122,400 KB
実行使用メモリ 50,844 KB
最終ジャッジ日時 2023-09-26 16:58:13
合計ジャッジ時間 2,867 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
50,528 KB
testcase_01 AC 22 ms
50,656 KB
testcase_02 AC 22 ms
50,576 KB
testcase_03 AC 22 ms
50,620 KB
testcase_04 AC 23 ms
50,684 KB
testcase_05 AC 22 ms
50,532 KB
testcase_06 AC 22 ms
50,588 KB
testcase_07 AC 22 ms
50,572 KB
testcase_08 AC 22 ms
50,708 KB
testcase_09 AC 32 ms
50,628 KB
testcase_10 AC 28 ms
50,532 KB
testcase_11 AC 24 ms
50,820 KB
testcase_12 AC 29 ms
50,680 KB
testcase_13 AC 25 ms
50,580 KB
testcase_14 AC 26 ms
50,620 KB
testcase_15 AC 24 ms
50,592 KB
testcase_16 AC 28 ms
50,680 KB
testcase_17 AC 22 ms
50,596 KB
testcase_18 AC 36 ms
50,524 KB
testcase_19 AC 23 ms
50,844 KB
testcase_20 AC 22 ms
50,520 KB
testcase_21 AC 35 ms
50,568 KB
testcase_22 AC 36 ms
50,540 KB
testcase_23 AC 36 ms
50,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<ctime>
//#include<atcoder/all>
using namespace std;
//  using namespace atcoder;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0)

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
//using mint = modint1000000007;

int dh[] = {-1,0,1,0};
int dw[] = {0,1,0,-1};

struct Combination{
    vector<long long> _fac,_finv,_inv;
    const int m = MOD;

    Combination(int sz) : _fac(sz),_finv(sz),_inv(sz){
        _fac[0] = _fac[1] = 1;
        _finv[0] = _finv[1] = 1;
        _inv[1] = 1;
        for(int i = 2; i <= sz; i++){
            _fac[i] = _fac[i-1]*i%m;
            _inv[i] = m-_inv[m%i]*(m/i)%m;
            _finv[i] = _finv[i-1]*_inv[i]%m;
        }
    }

    inline long long fac(int n){return _fac[n];}
    inline long long inv(int n){return _inv[n];}
    inline long long finv(int n){return _finv[n];}

    long long comb(int n,int k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return _fac[n]*(_finv[k]*_finv[n-k]%m)%m;
    }
};

int dp[110][100010];

int main(){
    Combination C(200000);
    int n,m; cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,110)rep(j,100010) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,n)rep(j,m+1){
        dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
        if(j-a[i] >= 0) dp[i+1][j] = min(dp[i+1][j],dp[i+1][j-a[i]] + 1);
    }
    ll ans = 0;
    rep(i,m+1){
        ans += C.comb(m-dp[n][i],i-dp[n][i]);
        ans %= MOD;
    }
    cout << ans << endl;
}

0