結果
| 問題 |
No.2383 Naphthol
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2023-07-16 10:39:39 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,724 bytes |
| コンパイル時間 | 130 ms |
| コンパイル使用メモリ | 31,488 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-17 12:40:28 |
| 合計ジャッジ時間 | 785 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 6 |
ソースコード
#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 + 1, K / 2) + combination(N + 1, K / 2 - 1): combination(N + 1, K / 2) * 2) % Mod;
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] % Mod, 2, Mod) + ans[3]) % Mod);
fflush(stdout);
return 0;
}