結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー takakintakakin
提出日時 2020-06-27 16:51:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 521 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 30,344 KB
最終ジャッジ日時 2023-09-19 05:27:30
合計ジャッジ時間 6,879 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,024 KB
testcase_01 AC 16 ms
8,124 KB
testcase_02 AC 16 ms
8,020 KB
testcase_03 AC 16 ms
7,972 KB
testcase_04 AC 17 ms
7,964 KB
testcase_05 AC 17 ms
7,972 KB
testcase_06 AC 16 ms
8,024 KB
testcase_07 AC 17 ms
7,784 KB
testcase_08 AC 16 ms
7,940 KB
testcase_09 AC 17 ms
7,920 KB
testcase_10 AC 16 ms
7,988 KB
testcase_11 AC 16 ms
7,992 KB
testcase_12 AC 16 ms
8,048 KB
testcase_13 AC 36 ms
9,312 KB
testcase_14 AC 37 ms
9,316 KB
testcase_15 AC 36 ms
9,420 KB
testcase_16 AC 36 ms
9,420 KB
testcase_17 AC 37 ms
9,312 KB
testcase_18 AC 36 ms
9,336 KB
testcase_19 AC 36 ms
9,452 KB
testcase_20 AC 37 ms
9,324 KB
testcase_21 AC 37 ms
9,460 KB
testcase_22 AC 37 ms
9,340 KB
testcase_23 AC 418 ms
29,876 KB
testcase_24 AC 416 ms
30,008 KB
testcase_25 AC 421 ms
30,068 KB
testcase_26 AC 425 ms
29,908 KB
testcase_27 AC 415 ms
29,928 KB
testcase_28 AC 303 ms
30,344 KB
testcase_29 AC 286 ms
29,884 KB
testcase_30 AC 368 ms
30,016 KB
testcase_31 AC 357 ms
29,928 KB
testcase_32 AC 367 ms
29,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
ans=float("inf")
L=[A[0]]
for i in range(1,n):
  L.append(min(L[-1],A[i]))
R=[A[-1]]
for i in range(n-1)[::-1]:
  R.append(min(R[-1],A[i]))
R=R[::-1]

for i in range(1,n-1):
  if L[i-1]<A[i] and R[i+1]<A[i]:
    ans=min(ans,L[i-1]+A[i]+R[i+1])

k=A.index(min(A))
if k==0 or k==n-1:
  if ans==float("inf"):
    print(-1)
  else:
    print(ans)
else:
  l,r=min(A[:k]),min(A[k+1:])
  ans=min(ans,l+r+A[k])
  print(ans)
0