結果
| 問題 |
No.2106 Wild Cacco
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 21:04:01 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,221 bytes |
| コンパイル時間 | 191 ms |
| コンパイル使用メモリ | 82,204 KB |
| 実行使用メモリ | 279,712 KB |
| 最終ジャッジ日時 | 2025-04-15 21:09:05 |
| 合計ジャッジ時間 | 4,559 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 7 TLE * 1 -- * 22 |
ソースコード
MOD = 998244353
s = input().strip()
n = len(s)
if n % 2 != 0:
print(0)
exit()
from collections import defaultdict
dp = defaultdict(int)
dp[(0, 0)] = 1
for c in s:
new_dp = defaultdict(int)
for (min_prev, max_prev), cnt in dp.items():
possible_chars = []
if c == '.':
possible_chars = ['(', ')', '?']
else:
possible_chars = [c]
for char in possible_chars:
if char == '(':
new_min = min_prev + 1
new_max = max_prev + 1
elif char == ')':
new_min = max(min_prev - 1, 0)
new_max = max_prev - 1
if new_max < 0:
continue
elif char == '?':
new_min = max(min_prev - 1, 0)
new_max = max_prev + 1
else:
assert False, "Invalid character"
if new_min > new_max:
continue
new_dp[(new_min, new_max)] = (new_dp[(new_min, new_max)] + cnt) % MOD
dp = new_dp
if not dp:
break
result = 0
for (min_b, max_b), cnt in dp.items():
if min_b <= 0 <= max_b:
result = (result + cnt) % MOD
print(result % MOD)
lam6er