結果

問題 No.2472 Tea time in the grand garden
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2023-08-06 23:02:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 1,083 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 162,092 KB
最終ジャッジ日時 2024-04-24 18:13:49
合計ジャッジ時間 7,344 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
143,616 KB
testcase_01 AC 148 ms
143,380 KB
testcase_02 AC 145 ms
143,744 KB
testcase_03 AC 213 ms
159,360 KB
testcase_04 AC 142 ms
142,976 KB
testcase_05 AC 139 ms
144,128 KB
testcase_06 AC 138 ms
143,104 KB
testcase_07 AC 145 ms
144,128 KB
testcase_08 AC 147 ms
143,872 KB
testcase_09 AC 138 ms
143,488 KB
testcase_10 AC 139 ms
142,932 KB
testcase_11 AC 141 ms
143,104 KB
testcase_12 AC 141 ms
143,232 KB
testcase_13 AC 199 ms
159,624 KB
testcase_14 AC 211 ms
159,480 KB
testcase_15 AC 210 ms
159,488 KB
testcase_16 AC 138 ms
143,604 KB
testcase_17 AC 139 ms
143,616 KB
testcase_18 AC 138 ms
143,872 KB
testcase_19 AC 142 ms
143,616 KB
testcase_20 AC 138 ms
143,488 KB
testcase_21 AC 141 ms
143,488 KB
testcase_22 AC 143 ms
143,488 KB
testcase_23 AC 138 ms
143,232 KB
testcase_24 AC 138 ms
143,520 KB
testcase_25 AC 184 ms
162,092 KB
testcase_26 AC 187 ms
160,892 KB
testcase_27 AC 150 ms
150,016 KB
testcase_28 AC 174 ms
160,256 KB
testcase_29 AC 187 ms
160,876 KB
testcase_30 AC 194 ms
161,740 KB
testcase_31 AC 184 ms
161,740 KB
testcase_32 AC 204 ms
159,488 KB
testcase_33 AC 203 ms
159,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

Tea Time (5) 想定解

O( max(N,K) ) Ver

"""

import sys
from sys import stdin

mod = 998244353

def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs

def modnCr(n,r):
    if n < 0 or r < 0 or n < r:
        return 0
    return fac[n] * inv[n-r] * inv[r] % mod

fac,inv = modfac(1000000,mod)

N,K = map(int,stdin.readline().split())

assert 1 <= N <= 200000
assert 0 <= K <= 200000

if K == 0:
    print (1)
    sys.exit()

# 括弧列のpeakがK個ある場合を考える
Kinv = pow(K,mod-2,mod)
ans = 0

for peak in range(1,K+1):

    # 括弧列の個数
    bracket_num = modnCr(K,peak) * modnCr(K,peak-1) * Kinv % mod

    # 隣り合う相異なる記号の個数
    diff_pos = peak*2-1

    ans += modnCr(2*K+N-diff_pos,N-diff_pos) * bracket_num
    ans %= mod

print (ans % mod)


0