結果

問題 No.2591 安上がりな括弧列
ユーザー 👑 H20H20
提出日時 2023-11-19 23:08:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,000 KB
最終ジャッジ日時 2023-12-18 23:30:04
合計ジャッジ時間 3,258 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,332 KB
testcase_01 AC 37 ms
53,332 KB
testcase_02 AC 35 ms
53,332 KB
testcase_03 AC 35 ms
53,332 KB
testcase_04 AC 35 ms
53,332 KB
testcase_05 AC 35 ms
53,332 KB
testcase_06 AC 36 ms
53,332 KB
testcase_07 AC 37 ms
53,332 KB
testcase_08 AC 41 ms
59,448 KB
testcase_09 AC 44 ms
61,716 KB
testcase_10 AC 44 ms
61,716 KB
testcase_11 AC 105 ms
75,996 KB
testcase_12 AC 99 ms
75,872 KB
testcase_13 AC 106 ms
76,000 KB
testcase_14 AC 104 ms
75,900 KB
testcase_15 AC 105 ms
75,908 KB
testcase_16 AC 99 ms
75,872 KB
testcase_17 AC 64 ms
72,516 KB
testcase_18 AC 79 ms
75,772 KB
testcase_19 AC 75 ms
75,772 KB
testcase_20 AC 108 ms
75,900 KB
testcase_21 AC 106 ms
75,880 KB
testcase_22 AC 100 ms
75,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = list(input())
A = list(map(int, input().split())) 
Left_cost = [0]*2*N
Right_cost = [0]*2*N
for i,(s,a) in enumerate(zip(S,A)):
    if s=='(':
        Right_cost[i]=a
    else:
        Left_cost[i]=a
inf = 10**18
DP = [inf]*2*N
DP[0]=0
for lc,rc in zip(Left_cost,Right_cost):
    NDP = [inf]*2*N
    for i in range(2*N):
        if i>0:
            NDP[i]=min(NDP[i],DP[i-1]+lc)
        if i<2*N-1:
            NDP[i]=min(NDP[i],DP[i+1]+rc)
    DP = NDP
print(DP[0])
0