結果

問題 No.2591 安上がりな括弧列
ユーザー 👑 rin204rin204
提出日時 2023-12-19 20:56:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 385 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 75,616 KB
最終ジャッジ日時 2023-12-19 20:56:20
合計ジャッジ時間 2,688 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 37 ms
53,460 KB
testcase_09 AC 45 ms
61,716 KB
testcase_10 AC 46 ms
61,716 KB
testcase_11 AC 80 ms
75,580 KB
testcase_12 AC 75 ms
75,588 KB
testcase_13 AC 83 ms
75,588 KB
testcase_14 AC 82 ms
75,616 KB
testcase_15 AC 80 ms
75,608 KB
testcase_16 AC 78 ms
75,592 KB
testcase_17 AC 82 ms
68,416 KB
testcase_18 AC 62 ms
72,652 KB
testcase_19 AC 59 ms
70,604 KB
testcase_20 AC 105 ms
75,616 KB
testcase_21 AC 77 ms
75,596 KB
testcase_22 AC 78 ms
75,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
S = input()
A = list(map(int, input().split()))
inf = 1 << 60
dp = [inf] * (n + 1)
dp[0] = 0
for s, a in zip(S, A):
    if s == "(":
        u = 0
        d = a
    else:
        u = a
        d = 0

    ndp = [inf] * (n + 1)
    for i in range(n):
        ndp[i] = min(ndp[i], dp[i + 1] + d)
        ndp[i + 1] = min(ndp[i + 1], dp[i] + u)
    dp = ndp

print(dp[0])
0