結果
問題 | 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 |
ソースコード
x, K = map(int, input().split())mod = 998244353p = x * pow(100, mod-2, mod) % moddef depth(S: str) -> int:d = 0res = 0for c in S:if c == '(':d += 1else:d -= 1if d < 0:return 0res = max(res, d)if d == 0:return resreturn 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) % modans = 0for d in range(K+1):ans += d * prob_by_depth[d] % modans %= modprint(ans)