結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー titiatitia
提出日時 2020-06-26 21:51:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 802 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 11,044 KB
実行使用メモリ 30,504 KB
最終ジャッジ日時 2023-09-18 04:11:02
合計ジャッジ時間 7,794 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,320 KB
testcase_01 AC 16 ms
7,984 KB
testcase_02 AC 16 ms
8,384 KB
testcase_03 AC 16 ms
8,316 KB
testcase_04 WA -
testcase_05 AC 17 ms
8,332 KB
testcase_06 AC 16 ms
8,364 KB
testcase_07 AC 16 ms
8,356 KB
testcase_08 WA -
testcase_09 AC 16 ms
8,356 KB
testcase_10 WA -
testcase_11 AC 16 ms
8,188 KB
testcase_12 WA -
testcase_13 AC 43 ms
9,364 KB
testcase_14 AC 47 ms
9,672 KB
testcase_15 WA -
testcase_16 AC 46 ms
9,580 KB
testcase_17 WA -
testcase_18 AC 43 ms
9,448 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 48 ms
9,616 KB
testcase_23 AC 632 ms
30,292 KB
testcase_24 AC 587 ms
30,036 KB
testcase_25 AC 643 ms
30,080 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 386 ms
30,332 KB
testcase_29 AC 363 ms
30,448 KB
testcase_30 AC 490 ms
30,080 KB
testcase_31 AC 482 ms
30,064 KB
testcase_32 AC 507 ms
30,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

MINL=[]
X=10**9
for a in A:
    X=min(a,X)
    MINL.append(X)

X=10**9
MINR=[]
for a in A[::-1]:
    X=min(a,X)
    MINR.append(X)

MINR=MINR[::-1]

ANS=3*10**9

for i in range(1,N-1):
    if A[i]>MINL[i-1] and A[i]>MINR[i+1]:
        ANS=min(ANS,A[i]+MINL[i-1]+MINR[i+1])

A1=A[0]
for i in range(1,N):
    if A[i]<A[i-1]:
        A1=A[i]
    else:
        break

#print(A1,i)
for j in range(i,N-1):
    if A[j]>A1 and MINR[j+1]<A[j]:
        ANS=min(ANS,A1+A[j]+MINR[j+1])

#print(ANS)


A1=A[-1]
for i in range(N-2,-1,-1):
    if A[i]<A[i+1]:
        A1=A[i]
    else:
        break

#print(A1,i)
 
for j in range(i,0,-1):
    if A[j]>A1 and MINL[j-1]<A[j]:
        ANS=min(ANS,A1+A[j]+MINL[j-1])


if ANS==3*10**9:
    print(-1)
else:
    print(ANS)
0