結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー GrayCoderGrayCoder
提出日時 2020-06-27 16:16:59
言語 PyPy3
(7.3.13)
結果
TLE  
実行時間 -
コード長 1,065 bytes
コンパイル時間 1,010 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 132,440 KB
最終ジャッジ日時 2023-09-19 04:42:50
合計ジャッジ時間 9,555 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,176 KB
testcase_01 AC 75 ms
71,424 KB
testcase_02 AC 76 ms
71,260 KB
testcase_03 AC 75 ms
71,340 KB
testcase_04 AC 76 ms
71,504 KB
testcase_05 AC 75 ms
71,376 KB
testcase_06 AC 75 ms
71,220 KB
testcase_07 AC 76 ms
71,300 KB
testcase_08 AC 75 ms
71,404 KB
testcase_09 AC 75 ms
71,476 KB
testcase_10 AC 75 ms
71,332 KB
testcase_11 AC 75 ms
71,372 KB
testcase_12 AC 74 ms
71,448 KB
testcase_13 AC 92 ms
76,184 KB
testcase_14 AC 86 ms
76,320 KB
testcase_15 AC 85 ms
76,028 KB
testcase_16 AC 84 ms
76,032 KB
testcase_17 AC 84 ms
76,280 KB
testcase_18 AC 86 ms
76,300 KB
testcase_19 AC 86 ms
76,216 KB
testcase_20 AC 84 ms
76,436 KB
testcase_21 AC 84 ms
76,228 KB
testcase_22 AC 85 ms
76,284 KB
testcase_23 AC 157 ms
132,128 KB
testcase_24 AC 156 ms
132,440 KB
testcase_25 AC 157 ms
132,088 KB
testcase_26 AC 157 ms
132,092 KB
testcase_27 AC 156 ms
132,312 KB
testcase_28 TLE -
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')
    a = A[:]
    n = min(a)
    while 1:
        if n == float('inf'):
            break
        i = a.index(n)
        if not i or i == N - 1:
            a[i] = float('inf')
        elif a[i-1] == float('inf') or a[i+1] == float('inf'):
            a[i] = float('inf')
        else:
            break
        n = min(a)
    if n != float('inf'):
        ans = min(a[:i]) + a[i] + min(a[i+1:])
    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])
    if isinstance(ans, float):
        print(-1)
    else:
        print(ans)


main()
0