結果

問題 No.2383 Naphthol
ユーザー minimumminimum
提出日時 2023-07-14 22:49:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,382 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 99,372 KB
最終ジャッジ日時 2023-10-14 13:06:14
合計ジャッジ時間 5,209 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 183 ms
99,164 KB
testcase_01 AC 180 ms
99,072 KB
testcase_02 AC 179 ms
99,068 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 185 ms
99,148 KB
testcase_10 AC 179 ms
99,232 KB
testcase_11 AC 178 ms
99,176 KB
testcase_12 AC 187 ms
99,212 KB
testcase_13 AC 189 ms
99,176 KB
testcase_14 AC 185 ms
99,172 KB
testcase_15 AC 185 ms
99,172 KB
testcase_16 AC 201 ms
99,172 KB
testcase_17 AC 182 ms
99,276 KB
testcase_18 AC 182 ms
99,264 KB
testcase_19 AC 180 ms
99,088 KB
testcase_20 AC 178 ms
99,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Combination:

    def __init__(self, MX=10**6, MOD=998244353):
        self.MX = MX
        self.MOD = MOD
        self.fact = [1] * (MX + 1)
        self.inv = [1] * (MX + 1)
        self.f_inv = [1] * (MX + 1)
        for i in range(2, MX + 1):
            self.fact[i] = (self.fact[i - 1] * i) % self.MOD
            self.inv[i] = ( - (self.MOD // i) * (self.inv[self.MOD % i])) % self.MOD
            self.f_inv[i] = (self.f_inv[i - 1] * self.inv[i]) % self.MOD
    
    def invs(self, n):
        if n <= self.MX:
            return self.inv[n]
        else:
            return pow(n, self.MOD - 2, self.MOD)
    
    def p(self, n, r):
        if r > n or r < 0:
            return 0
        return (self.fact[n] * self.f_inv[r]) % self.MOD
    
    def c(self, n, r):
        if r > n or r < 0:
            return 0
        return (self.fact[n] * self.f_inv[r] * self.f_inv[n - r]) % self.MOD


N, K = map(int, input().split())

if N == 1:
    ls = [-1, 1, 3, 4, 3, 1, 1]
    print(ls[K])

MOD = 998244353
com = Combination()


ans = com.c(2 * N + 4, K)

if K % 2 == 0:
    ans += com.c(N + 2, K // 2) * 2

if N % 2 == 0:
    if K % 2 == 0:
        ans += com.c(N + 2, K // 2)
else:
    if K % 2 == 0:
        ans += com.c(N + 1, K // 2)
        ans += com.c(N + 1, (K - 2) // 2)
    else:
        ans += com.c(N + 1, (K - 1) // 2) * 2

print((ans * com.invs(4)) % MOD)
0