結果

問題 No.2591 安上がりな括弧列
ユーザー tko919tko919
提出日時 2023-12-19 00:13:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 464 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 44,800 KB
最終ジャッジ日時 2023-12-19 00:13:59
合計ジャッジ時間 23,568 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

n=int(input())
S=str(input())
A=list(map(int,input().split()))

dp=[[10**18 for i in range(n*2+1)] for j in range(2*n+1)]
dp[0][0]=0 

for i in range(n*2):
	for j in range(n*2):
		if dp[i][j]!=10**18:
			if S[i]=='(':
				dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j])
				if j!=0:
					dp[i+1][j-1]=min(dp[i+1][j-1],dp[i][j]+A[i])
				
			else:
				if j!=0:
					dp[i+1][j-1]=min(dp[i+1][j+1],dp[i][j])
				dp[i+1][j+1]=min(dp[i+1][j-1],dp[i][j]+A[i])

print(dp[n*2][0])
0