結果

問題 No.2031 Colored Brackets
ユーザー H3PO4H3PO4
提出日時 2022-08-05 22:23:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 385 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 10,768 KB
実行使用メモリ 29,532 KB
最終ジャッジ日時 2023-10-13 23:37:52
合計ジャッジ時間 8,904 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
29,388 KB
testcase_01 AC 137 ms
29,340 KB
testcase_02 AC 134 ms
29,384 KB
testcase_03 AC 135 ms
29,528 KB
testcase_04 AC 162 ms
29,408 KB
testcase_05 AC 145 ms
29,272 KB
testcase_06 AC 151 ms
29,420 KB
testcase_07 AC 135 ms
29,388 KB
testcase_08 AC 176 ms
29,524 KB
testcase_09 AC 189 ms
29,532 KB
testcase_10 AC 205 ms
29,292 KB
testcase_11 AC 188 ms
29,356 KB
testcase_12 AC 210 ms
29,344 KB
testcase_13 AC 174 ms
29,432 KB
testcase_14 AC 216 ms
29,520 KB
testcase_15 AC 213 ms
29,356 KB
testcase_16 AC 211 ms
29,352 KB
testcase_17 AC 211 ms
29,512 KB
testcase_18 AC 215 ms
29,264 KB
testcase_19 AC 197 ms
29,364 KB
testcase_20 AC 182 ms
29,356 KB
testcase_21 AC 181 ms
29,388 KB
testcase_22 AC 183 ms
29,304 KB
testcase_23 AC 207 ms
29,508 KB
testcase_24 AC 133 ms
29,512 KB
testcase_25 AC 135 ms
29,480 KB
testcase_26 AC 133 ms
29,432 KB
testcase_27 AC 135 ms
29,472 KB
testcase_28 AC 135 ms
29,520 KB
testcase_29 AC 137 ms
29,268 KB
testcase_30 AC 135 ms
29,372 KB
testcase_31 AC 136 ms
29,512 KB
testcase_32 AC 135 ms
29,364 KB
testcase_33 AC 136 ms
29,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

N = int(input())
S = input()
MOD = 998244353
MAX = N // 2 + 2
dp = np.zeros(MAX, dtype=np.int64)
dp[0] = 1
left = 0
for s in S:
    if s == "(":
        new_dp = dp.copy()
        new_dp[1:] += dp[:-1]
        left += 1
    else:
        new_dp = dp.copy()
        new_dp[:-1] += dp[1:]
        new_dp[left:] = 0
        left -= 1
    dp = new_dp % MOD
print(dp[0])
0