結果

問題 No.1414 東大文系数学2021第2問改
ユーザー 👑 ygussanyygussany
提出日時 2021-02-28 22:06:05
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 981 bytes
コンパイル時間 579 ms
コンパイル使用メモリ 32,892 KB
実行使用メモリ 158,092 KB
最終ジャッジ日時 2024-04-12 10:49:58
合計ジャッジ時間 4,381 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 136 ms
157,948 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 132 ms
158,072 KB
testcase_05 AC 169 ms
158,048 KB
testcase_06 AC 133 ms
158,044 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 133 ms
158,036 KB
testcase_10 AC 168 ms
158,004 KB
testcase_11 AC 132 ms
158,036 KB
testcase_12 AC 133 ms
158,084 KB
testcase_13 AC 132 ms
157,936 KB
testcase_14 AC 158 ms
158,084 KB
testcase_15 AC 132 ms
158,044 KB
testcase_16 AC 133 ms
158,092 KB
testcase_17 AC 133 ms
157,920 KB
testcase_18 AC 133 ms
158,080 KB
testcase_19 AC 158 ms
158,016 KB
testcase_20 AC 159 ms
157,976 KB
testcase_21 AC 132 ms
157,080 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 132 ms
158,012 KB
testcase_24 AC 132 ms
158,012 KB
testcase_25 AC 133 ms
158,088 KB
testcase_26 AC 132 ms
158,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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

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 (n < 0 || k < 0 || n < k) return 0;
	return fact[n] * fact_inv[k] % Mod * fact_inv[n-k] % Mod;
}

int main()
{
	int N, M, K;
	scanf("%d %d %d", &N, &M, &K);

	int i;
	for (i = 1, fact[0] = 1; i <= N; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = N - 1, fact_inv[N] = div_mod(1, fact[N], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;

	long long ans = 0;
	for (i = 0; i <= M / K; i++) {
		if (i % 2 == 0) ans += combination(N - M + 1, i) * combination(N - K * i, M - K * i) % Mod;
		else ans += Mod - combination(N - M + 1, i) * combination(N - K * i, M - K * i) % Mod;
	}
	printf("%lld\n", (Mod + combination(N, M) - ans % Mod) % Mod);
	fflush(stdout);
	return 0;
}
0