結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー NoneNone
提出日時 2021-02-25 18:50:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 795 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 109,820 KB
最終ジャッジ日時 2024-04-08 16:51:50
合計ジャッジ時間 4,073 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 WA -
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 38 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 WA -
testcase_09 AC 37 ms
53,460 KB
testcase_10 WA -
testcase_11 AC 39 ms
53,460 KB
testcase_12 WA -
testcase_13 AC 53 ms
66,364 KB
testcase_14 AC 53 ms
66,364 KB
testcase_15 WA -
testcase_16 AC 53 ms
66,364 KB
testcase_17 WA -
testcase_18 AC 56 ms
66,364 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 56 ms
66,364 KB
testcase_23 AC 109 ms
109,812 KB
testcase_24 AC 108 ms
109,820 KB
testcase_25 AC 109 ms
109,820 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 99 ms
109,820 KB
testcase_29 AC 99 ms
108,276 KB
testcase_30 AC 112 ms
109,820 KB
testcase_31 AC 111 ms
109,820 KB
testcase_32 AC 112 ms
109,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right

# example()

N=int(input())
A=list(map(int, input().split()))


INF=float("inf")
left_u=[-1]*N
left_d=[INF]*N

u,d=-1,INF

for i in range(N):
    if u>A[i]:
        left_u[i]=u
    if d<A[i]:
        left_d[i]=d
    u=max(u,A[i])
    d=min(d,A[i])

right_u=[-1]*N
right_d=[INF]*N

u,d=-1,INF

for i in range(N)[::-1]:
    if u>A[i]:
        right_u[i]=u
    if d<A[i]:
        right_d[i]=d
    u=max(u,A[i])
    d=min(d,A[i])

res=INF
for i in range(1,N-1):
    if left_u[i]!=-1 and right_u[i]!=-1:
        res=min(A[i]+left_u[i]+right_u[i],res)
    if left_d[i]!=INF and right_d[i]!=INF:
        res=min(A[i]+left_d[i]+right_d[i],res)
    # print(i,A[i],left_u[i],right_u[i])


print(res if res!=INF else -1)

0