結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー GrayCoderGrayCoder
提出日時 2020-06-27 15:35:47
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 874 bytes
コンパイル時間 1,068 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 71,576 KB
最終ジャッジ日時 2023-09-19 03:30:34
合計ジャッジ時間 7,851 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,268 KB
testcase_01 AC 77 ms
71,268 KB
testcase_02 AC 77 ms
71,296 KB
testcase_03 AC 78 ms
71,172 KB
testcase_04 AC 77 ms
71,460 KB
testcase_05 AC 77 ms
71,576 KB
testcase_06 AC 77 ms
71,576 KB
testcase_07 AC 78 ms
71,276 KB
testcase_08 AC 78 ms
71,292 KB
testcase_09 AC 76 ms
71,340 KB
testcase_10 AC 77 ms
71,396 KB
testcase_11 AC 79 ms
71,492 KB
testcase_12 AC 78 ms
71,296 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))

    left, right = [A[0]], [A[-1]]
    min_ = A[0]
    for i in range(1, N):
        n = min(min_, A[i])
        left.append(n)
        min_ = n
    min_ = A[-1]
    for i in range(N - 2, -1, -1):
        n = min(min_, A[i])
        right.append(n)
        min_ = n
    right = right[::-1]

    ans = float('inf')
    for i in range(1, N - 1):
        if left[i-1] < A[i] > right[i+1]:
            ans = min(ans, left[i-1] + A[i] + right[i+1])
        l, r = sorted(A[:i]), sorted(A[i+1:])
        if l[-1] > A[i] < r[-1]:
            x, y = bisect(l, A[i]), bisect(r, A[i])
            ans = min(ans, l[x] + A[i] + r[y])
    if isinstance(ans, float):
        print(-1)
    else:
        print(ans)


main()
0