結果

問題 No.1832 NAND Reversible
ユーザー 👑 H20H20
提出日時 2021-12-13 20:39:38
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 472 ms
コンパイル使用メモリ 86,712 KB
実行使用メモリ 119,244 KB
最終ジャッジ日時 2023-10-13 18:23:31
合計ジャッジ時間 4,871 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,064 KB
testcase_01 AC 74 ms
71,156 KB
testcase_02 AC 73 ms
71,228 KB
testcase_03 AC 143 ms
117,856 KB
testcase_04 AC 126 ms
117,856 KB
testcase_05 AC 126 ms
117,268 KB
testcase_06 AC 126 ms
117,668 KB
testcase_07 AC 143 ms
118,312 KB
testcase_08 AC 126 ms
117,560 KB
testcase_09 AC 125 ms
117,532 KB
testcase_10 AC 124 ms
117,552 KB
testcase_11 AC 72 ms
71,124 KB
testcase_12 AC 74 ms
70,960 KB
testcase_13 AC 74 ms
71,148 KB
testcase_14 AC 73 ms
71,084 KB
testcase_15 AC 107 ms
95,520 KB
testcase_16 AC 120 ms
109,432 KB
testcase_17 AC 136 ms
112,612 KB
testcase_18 AC 129 ms
117,748 KB
testcase_19 AC 123 ms
112,552 KB
testcase_20 AC 125 ms
117,580 KB
testcase_21 AC 128 ms
117,596 KB
testcase_22 AC 124 ms
117,656 KB
testcase_23 AC 72 ms
71,216 KB
testcase_24 AC 73 ms
70,824 KB
testcase_25 AC 133 ms
119,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#コンビネーション
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


if K==0:
    print(1)
    exit()
if K==1 and N%2==0:
    print(2)
    exit()
if K==1 and N%2==1:
    print(N-2)
    exit()
ans = 0
temp = ((N-K)//2)*2+1
for i in range(0,temp,2):
    ans = (ans + (i+1)*cmb(N-2-i,K-2,mod))%mod

print(ans)
0