結果
問題 | No.1693 Invasion |
ユーザー | みここ |
提出日時 | 2021-10-01 21:31:08 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 1,466 bytes |
コンパイル時間 | 728 ms |
コンパイル使用メモリ | 71,284 KB |
実行使用メモリ | 5,544 KB |
最終ジャッジ日時 | 2023-09-26 16:30:41 |
合計ジャッジ時間 | 1,994 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
4,376 KB |
testcase_01 | AC | 3 ms
4,380 KB |
testcase_02 | AC | 3 ms
4,380 KB |
testcase_03 | AC | 9 ms
4,380 KB |
testcase_04 | AC | 3 ms
4,376 KB |
testcase_05 | AC | 9 ms
4,380 KB |
testcase_06 | AC | 8 ms
4,380 KB |
testcase_07 | AC | 5 ms
4,380 KB |
testcase_08 | AC | 9 ms
4,408 KB |
testcase_09 | AC | 16 ms
4,944 KB |
testcase_10 | AC | 9 ms
5,368 KB |
testcase_11 | AC | 6 ms
4,452 KB |
testcase_12 | AC | 10 ms
5,412 KB |
testcase_13 | AC | 10 ms
4,448 KB |
testcase_14 | AC | 10 ms
4,384 KB |
testcase_15 | AC | 10 ms
4,384 KB |
testcase_16 | AC | 14 ms
4,700 KB |
testcase_17 | AC | 3 ms
4,376 KB |
testcase_18 | AC | 18 ms
5,488 KB |
testcase_19 | AC | 5 ms
5,416 KB |
testcase_20 | AC | 11 ms
4,380 KB |
testcase_21 | AC | 18 ms
5,384 KB |
testcase_22 | AC | 18 ms
5,544 KB |
testcase_23 | AC | 18 ms
5,528 KB |
ソースコード
#include <iostream> #include <vector> using namespace std; typedef long long ll; const ll MOD = 998244353; const int INF = 10000000; long long modpow(long long x, long long n){ long long res = 1; long long mul = x; while(n){ if(n % 2) res = res * mul % MOD; mul = mul * mul % MOD; n /= 2; } return res; } struct Combination { int maxn; std::vector<long long> fact; std::vector<long long> ifact; Combination(int maxn) : maxn(maxn){ fact.resize(maxn + 1); ifact.resize(maxn + 1); fact[0] = 1; for(int i = 1; i <= maxn; i++) fact[i] = fact[i - 1] * i % MOD; ifact[maxn] = modpow(fact[maxn], MOD - 2); for(int i = maxn - 1; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1) % MOD; } long long com(int n, int k){ if(k > n || k < 0) return 0; if(k == n || k == 0) return 1; return (fact[n] * ifact[k] % MOD) * ifact[n - k] % MOD; } }; int main() { int n, m; cin >> n >> m; int a[102]; for(int i = 0; i < n; i++) cin >> a[i]; int dp[100005]; dp[0] = 0; for(int i = 1; i <= m; i++) dp[i] = INF; for(int i = 0; i < n; i++){ int d[100005]; for(int j = 0; j <= m; j++) d[j] = dp[j]; for(int j = a[i]; j <= m; j++) d[j] = min(d[j], d[j - a[i]] + 1); swap(dp, d); } ll ans = 0; Combination com(m); for(int i = 0; i <= m; i++){ ans = (ans + com.com(m - dp[i], i - dp[i])) % MOD; } cout << ans << endl; }