結果

問題 No.1693 Invasion
ユーザー rtyurtyu
提出日時 2021-10-13 10:13:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 978 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 67,732 KB
実行使用メモリ 5,556 KB
最終ジャッジ日時 2023-10-17 19:03:07
合計ジャッジ時間 2,734 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 11 ms
4,996 KB
testcase_10 AC 8 ms
5,532 KB
testcase_11 AC 4 ms
4,468 KB
testcase_12 AC 9 ms
5,552 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 7 ms
4,428 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 16 ms
5,556 KB
testcase_19 AC 4 ms
5,552 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 15 ms
5,476 KB
testcase_22 AC 15 ms
5,500 KB
testcase_23 AC 15 ms
5,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

const long long md = 998244353;
int a[109], d[100009], inf = 1000000000;
long long ft[100009], rt[100009];

long long fp(long long n, long long k)
{
	long long s = 1;
	while (k) {
		if (k & 1) s = (s * n) % md;
		n = (n * n) % md; k /= 2;
	}
	return s;
}

long long cb(int n, int k)
{
	return (((ft[n] * rt[k]) % md) * rt[n - k]) % md;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	ft[0] = rt[0] = 1;
	for (int i = 1; i <= m; i++)
		ft[i] = (ft[i - 1] * i) % md;
	rt[m] = fp(ft[m], md - 2);
	for (int i = m - 1; i >= 1; i--)
		rt[i] = (rt[i + 1] * (i + 1)) % md;
	d[0] = 0;
	long long ans = 1;
	for (int i = 1; i <= m; i++) {
		d[i] = inf;
		for (int j = 1; j <= n; j++)
			if (a[j] <= i)
				d[i] = min(d[i], d[i - a[j]] + 1);
		if (d[i] != inf)
			ans = (ans + cb(m - d[i], i - d[i])) % md;
	}
	cout << ans << '\n';
	return 0;
}
0