結果

問題 No.2031 Colored Brackets
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2022-08-06 00:39:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 135,676 KB
最終ジャッジ日時 2023-10-14 02:57:00
合計ジャッジ時間 6,846 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,120 KB
testcase_01 AC 71 ms
71,004 KB
testcase_02 AC 72 ms
71,120 KB
testcase_03 AC 82 ms
75,832 KB
testcase_04 AC 140 ms
90,504 KB
testcase_05 AC 99 ms
76,348 KB
testcase_06 AC 118 ms
89,844 KB
testcase_07 AC 76 ms
75,896 KB
testcase_08 AC 180 ms
112,196 KB
testcase_09 AC 199 ms
112,652 KB
testcase_10 AC 242 ms
135,248 KB
testcase_11 AC 198 ms
112,060 KB
testcase_12 AC 248 ms
135,376 KB
testcase_13 AC 172 ms
109,904 KB
testcase_14 AC 257 ms
135,676 KB
testcase_15 AC 256 ms
135,248 KB
testcase_16 AC 252 ms
135,448 KB
testcase_17 AC 268 ms
135,252 KB
testcase_18 AC 236 ms
135,660 KB
testcase_19 AC 223 ms
134,276 KB
testcase_20 AC 167 ms
112,500 KB
testcase_21 AC 172 ms
112,296 KB
testcase_22 AC 179 ms
112,496 KB
testcase_23 AC 235 ms
135,548 KB
testcase_24 AC 72 ms
71,072 KB
testcase_25 AC 72 ms
71,120 KB
testcase_26 AC 73 ms
71,252 KB
testcase_27 AC 76 ms
75,908 KB
testcase_28 AC 73 ms
71,092 KB
testcase_29 AC 74 ms
71,336 KB
testcase_30 AC 71 ms
71,176 KB
testcase_31 AC 82 ms
76,156 KB
testcase_32 AC 72 ms
71,268 KB
testcase_33 AC 84 ms
76,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


n=int(input())
mod=998244353
s=[0]+list(input())
for i in range(1,n+1):
    if s[i]=="(":s[i]=1
    else:s[i]=-1

wa=[0]*(n+1)
for i in range(1,n+1):
    wa[i]=wa[i-1]+s[i]
dp=[[0]*(n+10) for i in range(n+3)]
dp[0][0]=1
for i in range(n):
    for red in range(n+1):
        dp[i][red]%=mod
        res=dp[i][red]
        blue=wa[i]-red
        if blue<0:continue
        if red+s[i+1]>=0:dp[i+1][red+s[i+1]]+=res
        if blue+s[i+1]>=0:dp[i+1][red]+=res


print(dp[n][0]%mod)

0