結果

問題 No.2591 安上がりな括弧列
ユーザー ニックネームニックネーム
提出日時 2023-12-25 17:24:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 292 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 75,760 KB
最終ジャッジ日時 2023-12-25 17:24:09
合計ジャッジ時間 2,896 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,332 KB
testcase_01 AC 36 ms
53,332 KB
testcase_02 AC 36 ms
53,332 KB
testcase_03 AC 37 ms
53,332 KB
testcase_04 AC 37 ms
53,332 KB
testcase_05 AC 37 ms
53,332 KB
testcase_06 AC 37 ms
53,332 KB
testcase_07 AC 36 ms
53,332 KB
testcase_08 AC 37 ms
53,332 KB
testcase_09 AC 50 ms
63,928 KB
testcase_10 AC 45 ms
61,856 KB
testcase_11 AC 94 ms
75,728 KB
testcase_12 AC 109 ms
75,632 KB
testcase_13 AC 107 ms
75,740 KB
testcase_14 AC 117 ms
75,664 KB
testcase_15 AC 119 ms
75,664 KB
testcase_16 AC 112 ms
75,632 KB
testcase_17 AC 70 ms
70,496 KB
testcase_18 AC 86 ms
75,632 KB
testcase_19 AC 77 ms
73,080 KB
testcase_20 AC 124 ms
75,676 KB
testcase_21 AC 111 ms
75,632 KB
testcase_22 AC 115 ms
75,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input()
a = list(map(int,input().split()))
dp = [0]+[10**12]*n
for i,(t,v) in enumerate(zip(s,a)):
    eq = [10**12]*(n+1)
    for i in range(n): eq[i+1] = min(eq[i+1],dp[i]+v*(t==")"))
    for i in range(n): eq[i] = min(eq[i],dp[i+1]+v*(t=="("))
    dp = eq
print(dp[0])
0