結果
| 問題 |
No.2106 Wild Cacco
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-22 11:46:11 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 794 ms / 2,000 ms |
| コード長 | 1,563 bytes |
| コンパイル時間 | 175 ms |
| コンパイル使用メモリ | 81,904 KB |
| 実行使用メモリ | 79,616 KB |
| 最終ジャッジ日時 | 2024-07-01 14:38:27 |
| 合計ジャッジ時間 | 13,357 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 30 |
ソースコード
import sys, random
input = lambda : sys.stdin.readline().rstrip()
write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18
LI = lambda : list(map(int, input().split())); II=lambda : int(input()); SI=lambda : [ord(c)-ord("a") for c in input()]
def debug(_l_):
for s in _l_.split():
print(f"{s}={eval(s)}", end=" ")
print()
def dlist(*l, fill=0):
if len(l)==1:
return [fill]*l[0]
ll = l[1:]
return [dlist(*ll, fill=fill) for _ in range(l[0])]
s = input()
n = len(s)
dp = [[0]*(n+1) for _ in range(2)]
dp[0][0] = 1
M = 998244353
for i in range(n):
ndp = [[0]*(n+1) for _ in range(2)]
if s[i]=="(":
l = [1]
elif s[i]==")":
l = [-1]
elif s[i]=="?":
l = [2,-2]
else:
l = [1,2,-1,-2]
for b in range(2):
for j in range(n+1):
val = dp[b][j]
if val==0:
continue
for v in l:
if v>0:
if v==1 or b==0:
ndp[b][j+1] += val
ndp[b][j+1] %= M
elif j>0:
if v==-1:
ndp[b][j-1] += val
ndp[b][j-1] %= M
else:
# v = -2
ndp[1][j-1] += val
ndp[1][j-1] %= M
dp = ndp
# print(dp)
ans = dp[0][0] + dp[1][0]
print(ans%M)