結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー GrayCoderGrayCoder
提出日時 2020-06-27 15:40:14
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 776 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 268,084 KB
最終ジャッジ日時 2023-09-19 03:41:45
合計ジャッジ時間 9,218 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,564 KB
testcase_01 AC 77 ms
71,356 KB
testcase_02 AC 78 ms
71,104 KB
testcase_03 AC 85 ms
75,020 KB
testcase_04 AC 80 ms
75,064 KB
testcase_05 AC 80 ms
75,484 KB
testcase_06 AC 82 ms
75,124 KB
testcase_07 AC 82 ms
75,204 KB
testcase_08 AC 82 ms
75,232 KB
testcase_09 AC 82 ms
75,300 KB
testcase_10 AC 82 ms
75,180 KB
testcase_11 AC 81 ms
75,068 KB
testcase_12 AC 82 ms
75,484 KB
testcase_13 AC 301 ms
77,496 KB
testcase_14 AC 295 ms
77,192 KB
testcase_15 AC 297 ms
77,428 KB
testcase_16 AC 302 ms
77,448 KB
testcase_17 AC 302 ms
77,236 KB
testcase_18 AC 299 ms
77,540 KB
testcase_19 AC 300 ms
77,764 KB
testcase_20 AC 304 ms
77,136 KB
testcase_21 AC 299 ms
77,212 KB
testcase_22 AC 299 ms
77,604 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = min(A[:i]), min(A[i+1:])
        if l > A[i] < r:
            ans = min(ans, l + A[i] + r)
    if isinstance(ans, float):
        print(-1)
    else:
        print(ans)


main()
0