結果

問題 No.2383 Naphthol
ユーザー 👑 ygussanyygussany
提出日時 2023-07-16 10:32:40
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,686 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 31,536 KB
実行使用メモリ 5,040 KB
最終ジャッジ日時 2023-10-17 14:55:19
合計ジャッジ時間 1,004 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 0 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 4 ms
5,028 KB
testcase_10 WA -
testcase_11 AC 3 ms
5,028 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 3 ms
4,620 KB
testcase_15 AC 2 ms
4,620 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 3 ms
4,724 KB
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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

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 N, K;
	scanf("%d %d", &N, &K);
	if (N == 1) {
		switch (K) {
		case 1:
			printf("1\n");
			break;
		case 2:
			printf("3\n");
			break;
		case 3:
			printf("3\n");
			break;
		case 4:
			printf("3\n");
			break;
		case 5:
			printf("1\n");
			break;
		case 6:
			printf("1\n");
			break;
		}
		return 0;
	}
	
	int i;
	for (i = 1, fact[0] = 1; i <= N * 2 + 4; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = N * 2 + 3, fact_inv[N*2+4] = div_mod(1, fact[N*2+4], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;
	
	long long ans[4] = {combination(N * 2 + 4, K)};
	if (N % 2 == 0) {
		ans[1] = (K % 2 == 0)? combination(N + 2, K / 2): 0;
		ans[2] = (K % 2 == 0)? combination(N + 2, K / 2): 0;
		ans[3] = (K % 4 == 0)? combination(N / 2 + 1, K / 4): 0;
	} else {
		ans[1] = (K % 2 == 0)? combination(N + 2 - 1, K / 2): combination(N + 2 - 1, K / 2) * 2;
		ans[2] = (K % 2 == 0)? combination(N + 2, K / 2): 0;
		ans[3] = ((K % 4 == 0)? combination(N / 2 + 1, K / 4): 0) + ((K % 4 == 2)? combination(N / 2 + 1, K / 4): 0);
	}
	ans[0] += Mod * 2 - (ans[1] + ans[2] - ans[3]);
	ans[1] += Mod - ans[3];
	ans[2] += Mod - ans[3];
	printf("%lld\n", (div_mod(ans[0] % Mod, 4, Mod) + div_mod(ans[1] % Mod, 2, Mod) + div_mod(ans[2], 2, Mod) + ans[3]) % Mod);
	fflush(stdout);
	return 0;
}
0