結果

問題 No.1414 東大文系数学2021第2問改
ユーザー 👑 ygussanyygussany
提出日時 2021-02-28 22:05:14
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 941 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 32,128 KB
実行使用メモリ 158,148 KB
最終ジャッジ日時 2024-04-12 10:48:51
合計ジャッジ時間 4,411 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 126 ms
158,084 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 120 ms
158,060 KB
testcase_05 TLE -
testcase_06 AC 120 ms
158,040 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,948 KB
testcase_09 AC 127 ms
158,104 KB
testcase_10 TLE -
testcase_11 AC 120 ms
158,076 KB
testcase_12 AC 119 ms
158,112 KB
testcase_13 AC 119 ms
158,100 KB
testcase_14 AC 137 ms
158,096 KB
testcase_15 AC 118 ms
157,932 KB
testcase_16 AC 116 ms
158,020 KB
testcase_17 AC 118 ms
158,092 KB
testcase_18 AC 118 ms
158,120 KB
testcase_19 AC 138 ms
158,004 KB
testcase_20 AC 136 ms
157,968 KB
testcase_21 AC 116 ms
157,184 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 117 ms
157,976 KB
testcase_24 AC 118 ms
158,044 KB
testcase_25 AC 145 ms
157,964 KB
testcase_26 AC 118 ms
158,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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

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)
{
	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