結果

問題 No.2591 安上がりな括弧列
ユーザー KoiKoi
提出日時 2023-12-19 01:01:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 91,264 KB
最終ジャッジ日時 2023-12-19 01:01:12
合計ジャッジ時間 3,339 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 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 36 ms
53,332 KB
testcase_05 AC 36 ms
53,332 KB
testcase_06 AC 35 ms
53,332 KB
testcase_07 AC 35 ms
53,332 KB
testcase_08 AC 37 ms
53,332 KB
testcase_09 AC 51 ms
63,948 KB
testcase_10 AC 48 ms
63,940 KB
testcase_11 AC 133 ms
91,136 KB
testcase_12 AC 143 ms
90,624 KB
testcase_13 AC 138 ms
91,264 KB
testcase_14 AC 136 ms
91,264 KB
testcase_15 AC 137 ms
91,264 KB
testcase_16 AC 138 ms
91,264 KB
testcase_17 AC 75 ms
72,968 KB
testcase_18 AC 102 ms
83,420 KB
testcase_19 AC 93 ms
81,536 KB
testcase_20 AC 133 ms
90,880 KB
testcase_21 AC 145 ms
91,264 KB
testcase_22 AC 140 ms
90,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
S=list(input())
A=list(map(int,input().split()))
dp=[[10**18]*(N+1) for _ in range(2*N+1)]
dp[0][0]=0
for i in range(2*N):
    for j in range(N+1):
        if(S[i]=="("):
            if(j<N):
                dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j])
            if(0<j):
                dp[i+1][j-1]=min(dp[i+1][j-1],dp[i][j]+A[i])
        else:
            if(j<N):
                dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+A[i])
            if(0<j):
                dp[i+1][j-1]=min(dp[i+1][j-1],dp[i][j])
print(dp[2*N][0])
0