結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 35 ms
53,460 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 41 ms
59,848 KB
testcase_09 AC 44 ms
61,988 KB
testcase_10 AC 43 ms
59,760 KB
testcase_11 AC 118 ms
90,996 KB
testcase_12 AC 110 ms
90,996 KB
testcase_13 AC 120 ms
90,996 KB
testcase_14 AC 114 ms
90,996 KB
testcase_15 AC 114 ms
90,996 KB
testcase_16 AC 115 ms
90,996 KB
testcase_17 AC 62 ms
72,516 KB
testcase_18 AC 91 ms
90,624 KB
testcase_19 AC 84 ms
86,796 KB
testcase_20 AC 118 ms
91,124 KB
testcase_21 AC 115 ms
90,996 KB
testcase_22 AC 117 ms
90,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF=pow(2,61)-1
N=int(input())
S=input()
A=list(map(int,input().split()))
dp=[[INF]*(N*2+2) for i in range(N*2+1)]
dp[0][0]=0
for i in range(N*2):
	for j in range(N*2+1):
		if dp[i][j]>=INF:
			continue
		if S[i]=="(":
			dp[i+1][j+1]=min(dp[i][j],dp[i+1][j+1])
			dp[i+1][j-1]=min(dp[i][j]+A[i],dp[i+1][j-1])
		else:
			dp[i+1][j+1]=min(dp[i][j]+A[i],dp[i+1][j+1])
			dp[i+1][j-1]=min(dp[i][j],dp[i+1][j-1])
print(dp[-1][0])
0