結果

問題 No.1832 NAND Reversible
ユーザー rlangevinrlangevin
提出日時 2024-02-09 12:39:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,159 bytes
コンパイル時間 3,576 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 84,656 KB
最終ジャッジ日時 2024-02-09 12:39:25
合計ジャッジ時間 3,082 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,460 KB
testcase_01 AC 31 ms
53,460 KB
testcase_02 AC 32 ms
53,460 KB
testcase_03 AC 101 ms
83,216 KB
testcase_04 AC 32 ms
53,460 KB
testcase_05 AC 31 ms
53,460 KB
testcase_06 AC 61 ms
69,872 KB
testcase_07 AC 82 ms
83,760 KB
testcase_08 AC 31 ms
53,460 KB
testcase_09 AC 30 ms
53,460 KB
testcase_10 AC 68 ms
83,224 KB
testcase_11 AC 31 ms
53,460 KB
testcase_12 AC 30 ms
53,460 KB
testcase_13 AC 46 ms
67,368 KB
testcase_14 AC 45 ms
67,368 KB
testcase_15 AC 73 ms
82,232 KB
testcase_16 AC 74 ms
84,472 KB
testcase_17 AC 77 ms
83,216 KB
testcase_18 AC 77 ms
83,272 KB
testcase_19 AC 77 ms
83,272 KB
testcase_20 AC 32 ms
53,460 KB
testcase_21 AC 31 ms
53,460 KB
testcase_22 AC 56 ms
69,868 KB
testcase_23 AC 31 ms
53,460 KB
testcase_24 AC 60 ms
67,368 KB
testcase_25 AC 80 ms
84,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
if K == 0:
    print(1)
    exit()
if K == 1:
    if N % 2 == 0:
        print(2)
    else:
        print(N - 2)
    exit()
mod = 998244353
N, K = N - 2, K - 2
if K == 0:
    print(pow((N+2)//2, 2, mod))
    exit()
if K == N:
    print(1)
    exit()

n = 505050
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod

ans = 0
for i in range(1, N):
    x = i + 1
    y = 1
    dx = N - x
    dy = K - y
    a = min(dx, dy)
    b = max(dx - a, dy - a)
    if a < 0 or b < 0:
        break
    if dx < dy:
        break
    ans += comb(a+b,a) * pow((i+2)//2, 2, mod)
    ans %= mod
    
for i in range(1, N):
    x = i + 1
    y = i
    dx = N - x
    dy = K - y
    a = min(dx, dy)
    b = max(dx - a, dy - a)
    if a < 0 or b < 0:
        break
    if dx < dy:
        break
    ans += comb(a+b,a)
    ans %= mod
    
print(ans)
0