結果

問題 No.2591 安上がりな括弧列
ユーザー ニックネームニックネーム
提出日時 2023-12-25 17:23:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 292 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 11,776 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2023-12-25 17:23:46
合計ジャッジ時間 26,779 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
9,984 KB
testcase_01 AC 30 ms
9,984 KB
testcase_02 AC 30 ms
9,984 KB
testcase_03 AC 29 ms
9,984 KB
testcase_04 AC 30 ms
9,984 KB
testcase_05 AC 30 ms
9,984 KB
testcase_06 AC 29 ms
9,984 KB
testcase_07 AC 30 ms
9,984 KB
testcase_08 AC 31 ms
9,984 KB
testcase_09 AC 38 ms
10,112 KB
testcase_10 AC 35 ms
9,984 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 AC 587 ms
10,112 KB
testcase_18 AC 1,134 ms
10,240 KB
testcase_19 AC 858 ms
10,240 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
権限があれば一括ダウンロードができます

ソースコード

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