結果

問題 No.1693 Invasion
ユーザー 👑 ygussanyygussany
提出日時 2021-09-26 16:44:22
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,125 bytes
コンパイル時間 1,198 ms
コンパイル使用メモリ 30,292 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 16:12:23
合計ジャッジ時間 2,307 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 3 ms
4,384 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 15 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 15 ms
4,380 KB
testcase_22 AC 16 ms
4,380 KB
testcase_23 AC 16 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int Mod = 998244353;
long long fact[100001], fact_inv[100001];

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

long long combination(int n, int k)
{
	if (k < 0 || n < k) return 0;
	return fact[n] * fact_inv[k] % Mod * fact_inv[n-k] % Mod;
}


int main()
{
	int i, N, M, A[101];
	scanf("%d %d", &N, &M);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	for (i = 1, fact[0] = 1; i <= M; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = M - 1, fact_inv[M] = div_mod(1, fact[M], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;

	int j, dist[100001], q[100001], head, tail;
	long long ans = 0;
	for (i = 1, dist[0] = 0; i <= M; i++) dist[i] = -1;
	q[0] = 0;
	for (head = 0, tail = 1; head < tail; head++) {
		i = q[head];
		ans += combination(M - dist[i], i - dist[i]);
		for (j = 1; j <= N; j++) {
			if (i + A[j] <= M && dist[i + A[j]] < 0) {
				dist[i + A[j]] = dist[i] + 1;
				q[tail++] = i + A[j];
			}
		}
	}
	printf("%lld\n", ans % Mod);
	fflush(stdout);
	return 0;
}
0