結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー 👑 H20H20
提出日時 2021-08-04 10:10:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 533 bytes
コンパイル時間 499 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 103,136 KB
最終ジャッジ日時 2023-10-14 21:13:52
合計ジャッジ時間 6,344 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,216 KB
testcase_01 AC 76 ms
71,184 KB
testcase_02 AC 75 ms
71,144 KB
testcase_03 AC 75 ms
71,256 KB
testcase_04 AC 76 ms
71,184 KB
testcase_05 AC 76 ms
71,332 KB
testcase_06 AC 76 ms
71,188 KB
testcase_07 AC 77 ms
71,392 KB
testcase_08 AC 76 ms
71,180 KB
testcase_09 AC 76 ms
71,100 KB
testcase_10 AC 76 ms
71,248 KB
testcase_11 AC 75 ms
70,804 KB
testcase_12 AC 75 ms
71,260 KB
testcase_13 AC 85 ms
76,236 KB
testcase_14 AC 88 ms
76,304 KB
testcase_15 AC 87 ms
76,236 KB
testcase_16 AC 87 ms
76,404 KB
testcase_17 AC 86 ms
76,388 KB
testcase_18 AC 86 ms
76,280 KB
testcase_19 AC 85 ms
76,404 KB
testcase_20 AC 85 ms
76,396 KB
testcase_21 AC 85 ms
76,212 KB
testcase_22 AC 87 ms
76,392 KB
testcase_23 AC 139 ms
102,964 KB
testcase_24 AC 136 ms
103,004 KB
testcase_25 AC 139 ms
103,012 KB
testcase_26 AC 139 ms
102,976 KB
testcase_27 AC 139 ms
102,896 KB
testcase_28 AC 127 ms
100,016 KB
testcase_29 AC 129 ms
99,984 KB
testcase_30 AC 142 ms
102,688 KB
testcase_31 AC 145 ms
103,136 KB
testcase_32 AC 145 ms
103,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))
for i in range(N-1):
    if A[i]<A[i+1]:
        break
else:
    print(-1)
    exit()
for i in range(N-1):
    if A[i]>A[i+1]:
        break
else:
    print(-1)
    exit()
LMIN = [A[0]]*N
RMIN = [A[-1]]*N
for i in range(1,N):
    LMIN[i] = min(LMIN[i-1],A[i])
for i in reversed(range(N-1)):
    RMIN[i] = min(A[i],RMIN[i+1])
ans = 10**10
for i in range(1,N-1):
    if LMIN[i-1]<A[i]>RMIN[i+1] or LMIN[i-1]>A[i]<RMIN[i+1]: 
        ans = min(ans,LMIN[i-1]+A[i]+RMIN[i+1])
print(ans)
0