結果

問題 No.2872 Depth of the Parentheses
ユーザー 寝癖
提出日時 2024-08-24 13:39:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 769 ms / 2,000 ms
コード長 717 bytes
コンパイル時間 448 ms
コンパイル使用メモリ 82,340 KB
実行使用メモリ 175,908 KB
最終ジャッジ日時 2024-09-06 20:50:55
合計ジャッジ時間 21,425 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 TLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

x, K = map(int, input().split())
mod = 998244353
p = x * pow(100, mod-2, mod) % mod

def depth(S: str) -> int:
    d = 0
    res = 0
    for c in S:
        if c == '(':
            d += 1
        else:
            d -= 1
            if d < 0:
                return 0
        res = max(res, d)
    if d == 0:
        return res
    return 0

# 深さがdとなる確率
prob_by_depth = [0] * (K+1)

for bit in range(1<<(2*K)):
    S = ''
    for i in range(2*K):
        if bit & 1<<i:
            S += '('
        else:
            S += ')'
    d = depth(S)
    prob_by_depth[d] += pow(p, K, mod) * pow(1-p, K, mod) % mod

ans = 0
for d in range(K+1):
    ans += d * prob_by_depth[d] % mod
    ans %= mod
print(ans)
0