結果

問題 No.2031 Colored Brackets
ユーザー lilictakalilictaka
提出日時 2022-08-10 13:52:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 81,836 KB
実行使用メモリ 135,608 KB
最終ジャッジ日時 2023-10-20 23:57:27
合計ジャッジ時間 7,122 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,176 KB
testcase_01 AC 39 ms
53,176 KB
testcase_02 AC 38 ms
53,176 KB
testcase_03 AC 50 ms
61,676 KB
testcase_04 AC 138 ms
89,776 KB
testcase_05 AC 94 ms
83,548 KB
testcase_06 AC 115 ms
88,228 KB
testcase_07 AC 45 ms
59,584 KB
testcase_08 AC 194 ms
111,624 KB
testcase_09 AC 220 ms
112,116 KB
testcase_10 AC 277 ms
134,772 KB
testcase_11 AC 222 ms
111,824 KB
testcase_12 AC 282 ms
134,992 KB
testcase_13 AC 182 ms
107,976 KB
testcase_14 AC 287 ms
135,000 KB
testcase_15 AC 288 ms
135,000 KB
testcase_16 AC 289 ms
134,756 KB
testcase_17 AC 305 ms
135,120 KB
testcase_18 AC 274 ms
135,172 KB
testcase_19 AC 250 ms
132,436 KB
testcase_20 AC 190 ms
111,112 KB
testcase_21 AC 194 ms
112,748 KB
testcase_22 AC 192 ms
112,720 KB
testcase_23 AC 268 ms
135,608 KB
testcase_24 AC 39 ms
53,176 KB
testcase_25 AC 40 ms
53,176 KB
testcase_26 AC 38 ms
53,176 KB
testcase_27 AC 44 ms
59,584 KB
testcase_28 AC 38 ms
53,176 KB
testcase_29 AC 38 ms
53,176 KB
testcase_30 AC 38 ms
53,176 KB
testcase_31 AC 59 ms
65,816 KB
testcase_32 AC 38 ms
53,176 KB
testcase_33 AC 58 ms
65,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def acum(List):#累積和
    rev = [0 for _ in range(len(List))]
    for i in range(len(List)):
        if i == 0:
            rev[i] = List[i]
        else:
           rev[i] = rev[i-1] + List[i] 
    return rev
N = int(input())
S = [''] + list(input())
d = [0]
for s in S[1:]:
    if s == '(':
        d += [1]
    else:
        d += [-1]
d = acum(d)
dp = [[0] *(N+1) for _ in range(N+1)]
dp[0][0] = 1
mod = 998244353
for i in range(N):
    for r in range(N+1):
        if d[i+1]-r >= 0:
            dp[i+1][r] += dp[i][r]
        if S[i+1] == '(':
            if r + 1 <= N and d[i+1]-(r+1) >= 0:
                dp[i+1][r+1] += dp[i][r]
        else:
            if r -1 >= 0 and d[i+1]-(r-1) >= 0:
                dp[i+1][r-1] += dp[i][r]
        dp[i+1][r] %= mod
ans = dp[N][0]%mod
print(ans)
0