結果

問題 No.1832 NAND Reversible
ユーザー s1230149s1230149
提出日時 2022-07-07 13:37:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 821 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 125,752 KB
最終ジャッジ日時 2023-08-25 22:55:34
合計ジャッジ時間 36,921 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,263 ms
125,564 KB
testcase_01 WA -
testcase_02 AC 1,277 ms
125,588 KB
testcase_03 AC 1,421 ms
125,572 KB
testcase_04 WA -
testcase_05 AC 1,344 ms
125,640 KB
testcase_06 AC 1,226 ms
125,720 KB
testcase_07 AC 1,410 ms
125,580 KB
testcase_08 AC 1,387 ms
125,660 KB
testcase_09 WA -
testcase_10 AC 1,250 ms
125,636 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1,249 ms
125,620 KB
testcase_14 AC 1,259 ms
125,652 KB
testcase_15 AC 1,268 ms
125,720 KB
testcase_16 AC 1,283 ms
125,720 KB
testcase_17 AC 1,372 ms
125,576 KB
testcase_18 AC 1,249 ms
125,652 KB
testcase_19 AC 1,234 ms
125,688 KB
testcase_20 AC 1,245 ms
125,752 KB
testcase_21 AC 1,393 ms
125,744 KB
testcase_22 AC 1,407 ms
125,620 KB
testcase_23 WA -
testcase_24 AC 1,276 ms
125,564 KB
testcase_25 AC 1,325 ms
125,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 998244353
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

N, K = map(int, input().split())
K = N - K
# number of 1
mod = 998244353
ans = 0
for i in range(K+1):
    if i%2 == 1: continue
    if N - i == 0: ans += 1
    if N - i - 1 == 0: ans += i + 1
    if N - i - 2 < 0: continue
    a = i + 1
    b = cmb((N - i - 2), K - i, p)
    ans += a * b
    ans %= mod
print(ans%mod)
0