結果
| 問題 |
No.1693 Invasion
|
| ユーザー |
tnakao0123
|
| 提出日時 | 2021-10-05 12:21:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 2,000 ms |
| コード長 | 2,298 bytes |
| コンパイル時間 | 1,155 ms |
| コンパイル使用メモリ | 94,736 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-23 02:34:18 |
| 合計ジャッジ時間 | 2,103 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 1693.cc: No.1693 Invasion - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 100;
const int MAX_M = 100000;
const int MOD = 998244353;
const int INF = 1 << 30;
/* typedef */
/* typedef */
template<const int MOD>
struct MI {
int v;
MI(): v() {}
MI(int _v): v(_v % MOD) {}
MI(long long _v): v(_v % MOD) {}
MI operator+(const MI m) const { return MI((v + m.v) % MOD); }
MI operator-(const MI m) const { return MI((v + MOD - m.v) % MOD); }
MI operator*(const MI m) const { return MI((long long)v * m.v % MOD); }
MI &operator+=(const MI m) { return (*this = *this + m); }
MI &operator-=(const MI m) { return (*this = *this - m); }
MI &operator*=(const MI m) { return (*this = *this * m); }
MI pow(int n) const { // a^n % MOD
MI pm = 1, a = *this;
while (n > 0) {
if (n & 1) pm *= a;
a *= a;
n >>= 1;
}
return pm;
}
MI inv() const { return pow(MOD - 2); }
MI operator/(const MI m) const { return *this * m.inv(); }
MI &operator/=(const MI m) { return (*this = *this / m); }
};
typedef MI<MOD> mi;
/* global variables */
mi fs[MAX_M + 1], invfs[MAX_M + 1];
int as[MAX_N], dp[MAX_M + 1];
/* subroutines */
inline mi nck(int n, int k) { // nCk % MOD
return fs[n] * invfs[n - k] * invfs[k];
}
void prepare_fracs(int n) {
fs[0] = invfs[0] = 1;
for (int i = 1; i <= n; i++) {
fs[i] = fs[i - 1] * i;
invfs[i] = fs[i].inv();
}
}
/* subroutines */
inline void setmin(int &a, int b) { if (a > b) a = b; }
/* main */
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", as + i);
fill(dp, dp + m + 1, INF);
dp[0] = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j + as[i] <= m; j++)
if (dp[j] < INF) setmin(dp[j + as[i]], dp[j] + 1);
prepare_fracs(m);
mi sum = 0;
for (int i = 0; i <= m; i++)
if (dp[i] < INF) sum += nck(m - dp[i], i - dp[i]);
printf("%d\n", sum.v);
return 0;
}
tnakao0123