結果

問題 No.1095 Smallest Kadomatsu Subsequence
コンテスト
ユーザー ttr
提出日時 2020-06-26 22:29:53
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 629 ms / 2,000 ms
コード長 489 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 525 ms
コンパイル使用メモリ 20,700 KB
実行使用メモリ 42,644 KB
最終ジャッジ日時 2026-03-26 04:46:26
合計ジャッジ時間 8,346 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import heapq
N = int(input())
A = [int(a) for a in input().split()]

ans = 10**9
l = A[0]
h = []
for i in range(2, N):
    heapq.heappush(h, (A[i], i))

for i in range(1, N-1):
    while len(h) > 0 and h[0][1] <= i:
        heapq.heappop(h)
    if len(h) == 0:
        break
    if l < A[i] and h[0][0] < A[i]:
        ans = min(ans, l+A[i]+h[0][0])
    elif A[i] < l and A[i] < h[0][0]:
        ans = min(ans, l+A[i]+h[0][0])
    l = min(l, A[i])

if ans == 10**9:
    ans = -1
print(ans)
0