結果

問題 No.2031 Colored Brackets
ユーザー wattaiheiwattaihei
提出日時 2022-08-05 23:24:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 486 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 86,776 KB
実行使用メモリ 77,304 KB
最終ジャッジ日時 2023-10-14 01:16:55
合計ジャッジ時間 5,965 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,080 KB
testcase_01 AC 74 ms
71,036 KB
testcase_02 AC 74 ms
70,880 KB
testcase_03 AC 79 ms
75,812 KB
testcase_04 AC 119 ms
76,628 KB
testcase_05 AC 100 ms
77,048 KB
testcase_06 AC 108 ms
76,896 KB
testcase_07 AC 77 ms
75,864 KB
testcase_08 AC 140 ms
77,228 KB
testcase_09 AC 156 ms
77,124 KB
testcase_10 AC 177 ms
77,028 KB
testcase_11 AC 156 ms
77,116 KB
testcase_12 AC 183 ms
77,056 KB
testcase_13 AC 137 ms
76,996 KB
testcase_14 AC 186 ms
76,952 KB
testcase_15 AC 187 ms
77,304 KB
testcase_16 AC 186 ms
77,052 KB
testcase_17 AC 185 ms
77,288 KB
testcase_18 AC 181 ms
77,012 KB
testcase_19 AC 165 ms
76,984 KB
testcase_20 AC 140 ms
76,996 KB
testcase_21 AC 141 ms
76,944 KB
testcase_22 AC 144 ms
77,144 KB
testcase_23 AC 177 ms
76,956 KB
testcase_24 AC 73 ms
70,880 KB
testcase_25 AC 72 ms
71,068 KB
testcase_26 AC 74 ms
71,180 KB
testcase_27 AC 80 ms
76,316 KB
testcase_28 AC 70 ms
71,068 KB
testcase_29 AC 72 ms
70,844 KB
testcase_30 AC 72 ms
70,964 KB
testcase_31 AC 84 ms
76,292 KB
testcase_32 AC 71 ms
70,844 KB
testcase_33 AC 87 ms
76,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod = 998244353

N = int(input())
S = list(input().rstrip())

dp = [0]*(N+1)
dp[0] = 1
r = 0
for s in S:
    t = 1 if s == "(" else -1
    ndp = [0]*(N+1)
    for i in range(N):
        if t == 1:
            ndp[i+1] += dp[i]
            ndp[i] += dp[i]
        else:
            if i-1 >= 0:
                ndp[i-1] += dp[i]
            if r - i > 0:
                ndp[i] += dp[i]
        ndp[i-1] %= mod
    r += t
    dp = ndp

print(dp[0])
0