結果
| 問題 |
No.2106 Wild Cacco
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 21:09:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,127 bytes |
| コンパイル時間 | 196 ms |
| コンパイル使用メモリ | 82,000 KB |
| 実行使用メモリ | 277,796 KB |
| 最終ジャッジ日時 | 2025-04-15 21:15:13 |
| 合計ジャッジ時間 | 4,275 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 7 TLE * 1 -- * 22 |
ソースコード
MOD = 998244353
s = input().strip()
n = len(s)
if n % 2 != 0:
print(0)
exit()
current_dp = {(0, 0): 1}
for i in range(n):
next_dp = {}
char = s[i]
possible_chars = ['(', ')', '?'] if char == '.' else [char]
for (min_b, max_b), cnt in current_dp.items():
for c in possible_chars:
if c == '(':
new_min_p = min_b + 1
new_max_p = max_b + 1
elif c == ')':
new_min_p = min_b - 1
new_max_p = max_b - 1
else: # '?'
new_min_p = min_b - 1
new_max_p = max_b + 1
new_min = max(new_min_p, 0)
new_max = new_max_p
if new_max < 0 or new_min > new_max:
continue
key = (new_min, new_max)
next_dp[key] = (next_dp.get(key, 0) + cnt) % MOD
current_dp = next_dp
if not current_dp:
break # No possible ways left
ans = 0
for (min_b, max_b), cnt in current_dp.items():
if min_b <= 0 <= max_b:
ans = (ans + cnt) % MOD
print(ans)
lam6er