結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー ttrttr
提出日時 2020-06-26 22:29:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 899 ms / 2,000 ms
コード長 489 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 36,472 KB
最終ジャッジ日時 2023-09-18 05:55:04
合計ジャッジ時間 8,727 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,280 KB
testcase_01 AC 16 ms
8,188 KB
testcase_02 AC 19 ms
8,300 KB
testcase_03 AC 17 ms
8,132 KB
testcase_04 AC 16 ms
8,320 KB
testcase_05 AC 16 ms
8,188 KB
testcase_06 AC 16 ms
8,176 KB
testcase_07 AC 17 ms
8,244 KB
testcase_08 AC 16 ms
8,184 KB
testcase_09 AC 16 ms
8,328 KB
testcase_10 AC 17 ms
8,348 KB
testcase_11 AC 17 ms
8,124 KB
testcase_12 AC 16 ms
8,296 KB
testcase_13 AC 45 ms
9,676 KB
testcase_14 AC 40 ms
9,776 KB
testcase_15 AC 39 ms
9,688 KB
testcase_16 AC 45 ms
9,684 KB
testcase_17 AC 39 ms
9,756 KB
testcase_18 AC 45 ms
9,680 KB
testcase_19 AC 42 ms
9,604 KB
testcase_20 AC 42 ms
9,728 KB
testcase_21 AC 39 ms
9,608 KB
testcase_22 AC 45 ms
9,544 KB
testcase_23 AC 741 ms
36,356 KB
testcase_24 AC 507 ms
36,372 KB
testcase_25 AC 899 ms
36,136 KB
testcase_26 AC 631 ms
36,448 KB
testcase_27 AC 506 ms
36,296 KB
testcase_28 AC 607 ms
36,324 KB
testcase_29 AC 465 ms
36,472 KB
testcase_30 AC 609 ms
36,252 KB
testcase_31 AC 663 ms
36,232 KB
testcase_32 AC 620 ms
36,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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