結果
| 問題 |
No.2106 Wild Cacco
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:47:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,068 bytes |
| コンパイル時間 | 157 ms |
| コンパイル使用メモリ | 82,348 KB |
| 実行使用メモリ | 77,172 KB |
| 最終ジャッジ日時 | 2025-03-31 17:48:30 |
| 合計ジャッジ時間 | 4,863 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 7 TLE * 1 -- * 22 |
ソースコード
MOD = 998244353
from collections import defaultdict
s = input().strip()
n = len(s)
current_dp = defaultdict(int)
current_dp[(0, 0)] = 1
for i in range(n):
next_dp = defaultdict(int)
c = s[i]
replacements = []
if c == '.':
replacements = ['(', ')', '?']
else:
replacements = [c]
for (lo_prev, hi_prev), count in current_dp.items():
for char in replacements:
if char == '(':
new_lo = lo_prev + 1
new_hi = hi_prev + 1
elif char == ')':
new_lo = lo_prev - 1
new_hi = hi_prev - 1
else:
new_lo = lo_prev - 1
new_hi = hi_prev + 1
new_lo_clamped = max(new_lo, 0)
if new_hi >= new_lo_clamped:
next_dp[(new_lo_clamped, new_hi)] = (next_dp[(new_lo_clamped, new_hi)] + count) % MOD
current_dp = next_dp
result = 0
for (lo, hi), cnt in current_dp.items():
if lo <= 0 <= hi:
result = (result + cnt) % MOD
print(result)
lam6er