結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー GrayCoderGrayCoder
提出日時 2020-06-27 15:34:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 874 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 15,132 KB
最終ジャッジ日時 2023-09-19 03:28:40
合計ジャッジ時間 5,992 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
15,132 KB
testcase_01 AC 17 ms
8,016 KB
testcase_02 AC 18 ms
8,020 KB
testcase_03 AC 18 ms
7,980 KB
testcase_04 AC 18 ms
7,980 KB
testcase_05 AC 18 ms
8,076 KB
testcase_06 AC 18 ms
8,000 KB
testcase_07 AC 18 ms
8,080 KB
testcase_08 AC 18 ms
8,012 KB
testcase_09 AC 18 ms
8,088 KB
testcase_10 AC 18 ms
8,192 KB
testcase_11 AC 19 ms
7,948 KB
testcase_12 AC 18 ms
7,980 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