結果

問題 No.1693 Invasion
ユーザー uytvccuytvcc
提出日時 2021-10-02 02:01:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,891 bytes
コンパイル時間 1,814 ms
コンパイル使用メモリ 167,700 KB
実行使用メモリ 16,352 KB
最終ジャッジ日時 2023-09-27 02:19:10
合計ジャッジ時間 3,528 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
15,700 KB
testcase_01 AC 36 ms
15,664 KB
testcase_02 AC 36 ms
15,836 KB
testcase_03 AC 35 ms
15,636 KB
testcase_04 AC 38 ms
15,632 KB
testcase_05 AC 37 ms
15,708 KB
testcase_06 AC 36 ms
15,644 KB
testcase_07 AC 37 ms
15,708 KB
testcase_08 AC 37 ms
15,656 KB
testcase_09 AC 48 ms
16,072 KB
testcase_10 AC 43 ms
16,216 KB
testcase_11 AC 39 ms
15,856 KB
testcase_12 AC 43 ms
16,092 KB
testcase_13 AC 40 ms
15,792 KB
testcase_14 AC 41 ms
15,648 KB
testcase_15 AC 40 ms
15,700 KB
testcase_16 AC 44 ms
15,912 KB
testcase_17 AC 38 ms
15,636 KB
testcase_18 AC 54 ms
16,148 KB
testcase_19 AC 40 ms
16,164 KB
testcase_20 AC 37 ms
15,636 KB
testcase_21 AC 50 ms
16,060 KB
testcase_22 AC 50 ms
16,208 KB
testcase_23 AC 52 ms
16,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF 1000000007
#define LINF 1000000000000000007LL
#define PI 3.14159265359
#define P pair<ll,ll>
template <typename T>
inline bool chmax(T &a, const T &b){
  if(a<b) {a=b; return true;}
  else return false;
}
template <typename T>
inline bool chmin(T &a, const T &b){
  if(a>b) {a=b; return true;}
  else return false;
}
struct Edge{
  int to; ll cost;
  Edge(int to, ll cost) : to(to), cost(cost) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g,int from,int to,ll cost,bool rev,ll rev_cost){
  g[from].push_back(Edge(to,cost));
  if(rev) g[to].push_back(Edge(from,rev_cost));
}

ll dp[100005];
int a[110];

const int MAX = 510000; // 5*(10^5)

ll fac[MAX], finv[MAX], inv[MAX];

void init(int m) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

ll nCk(int n, int k,int m){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % m) % m;
}

ll nPk(int n, int k, int m){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n]*finv[n-k]%m;
}

void solve(){
  int n,m;
  cin>>n>>m;
  rep(i,n) cin>>a[i];

  rep(i,m+1) dp[i]=INF;
  dp[0]=0;
  for(int k=0; k<=m; k++)rep(i,n){
    if(k-a[i]>=0) chmin(dp[k],dp[k-a[i]]+1); 
  }
  
  init(MOD2);
  ll ans=0;
  for(int k=0; k<=m; k++){
    if(dp[k]!=INF) ans += nCk(m-dp[k],k-dp[k],MOD2);
    ans %=MOD2;
  }
  cout<<ans<<'\n';
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<setprecision(10)<<fixed;
  solve();
  return 0;
}
0