結果

問題 No.2031 Colored Brackets
ユーザー titiatitia
提出日時 2022-08-06 00:02:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 605 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 86,640 KB
実行使用メモリ 77,440 KB
最終ジャッジ日時 2023-10-14 02:17:00
合計ジャッジ時間 4,934 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,412 KB
testcase_01 AC 71 ms
70,784 KB
testcase_02 AC 71 ms
70,972 KB
testcase_03 AC 83 ms
76,440 KB
testcase_04 AC 102 ms
77,040 KB
testcase_05 AC 93 ms
76,496 KB
testcase_06 AC 96 ms
76,572 KB
testcase_07 AC 72 ms
70,904 KB
testcase_08 AC 108 ms
77,140 KB
testcase_09 AC 113 ms
77,088 KB
testcase_10 AC 120 ms
77,168 KB
testcase_11 AC 114 ms
77,212 KB
testcase_12 AC 122 ms
76,912 KB
testcase_13 AC 109 ms
77,112 KB
testcase_14 AC 125 ms
77,044 KB
testcase_15 AC 125 ms
77,200 KB
testcase_16 AC 122 ms
77,088 KB
testcase_17 AC 179 ms
77,440 KB
testcase_18 AC 88 ms
76,604 KB
testcase_19 AC 94 ms
76,728 KB
testcase_20 AC 93 ms
76,648 KB
testcase_21 AC 89 ms
76,640 KB
testcase_22 AC 93 ms
76,796 KB
testcase_23 AC 93 ms
76,556 KB
testcase_24 AC 71 ms
71,112 KB
testcase_25 AC 71 ms
71,276 KB
testcase_26 AC 71 ms
70,960 KB
testcase_27 AC 73 ms
71,128 KB
testcase_28 AC 71 ms
70,980 KB
testcase_29 AC 72 ms
71,180 KB
testcase_30 AC 73 ms
71,384 KB
testcase_31 AC 87 ms
75,980 KB
testcase_32 AC 74 ms
70,920 KB
testcase_33 AC 85 ms
76,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
S=input().strip()

mod=998244353

SUM=[0]
for s in S:
    if s=="(":
        SUM.append(SUM[-1]+1)
    else:
        SUM.append(SUM[-1]-1)

MAX=max(SUM)+1
DP=[0]*MAX
DP[0]=1

for i in range(N):
    NDP=[0]*MAX
    x=SUM[i+1]

    for j in range(MAX):
        if S[i]=="(":
            if j+1<MAX:
                NDP[j+1]+=DP[j]
            NDP[j]+=DP[j]
        else:
            if j-1>=0:
                NDP[j-1]+=DP[j]
            if x-j>=0:
                NDP[j]+=DP[j]

    DP=[x%mod for x in NDP]

print(DP[0])
            
        
        
0