結果
| 問題 |
No.2591 安上がりな括弧列
|
| コンテスト | |
| ユーザー |
H20
|
| 提出日時 | 2023-11-26 22:15:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 68 ms / 2,000 ms |
| コード長 | 495 bytes |
| コンパイル時間 | 182 ms |
| コンパイル使用メモリ | 82,536 KB |
| 実行使用メモリ | 69,864 KB |
| 最終ジャッジ日時 | 2024-09-27 08:31:06 |
| 合計ジャッジ時間 | 2,228 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
import heapq
N = int(input())
S = list(input())
A = list(map(int, input().split()))
ans = 0
h = []
cnt = 0
for s,a in zip(S,A):
if s=='(':
cnt+=1
else:
heapq.heappush(h,a)
cnt-=1
if cnt<0:
cnt+=2
ans+=heapq.heappop(h)
h = []
cnt = 0
for s,a in zip(S[::-1],A[::-1]):
if s==')':
cnt+=1
else:
heapq.heappush(h,a)
cnt-=1
if cnt<0:
cnt+=2
ans+=heapq.heappop(h)
print(ans)
H20