結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー O2MTO2MT
提出日時 2020-08-15 18:59:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 377 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 32,560 KB
最終ジャッジ日時 2024-04-19 03:16:04
合計ジャッジ時間 5,856 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 29 ms
10,880 KB
testcase_04 AC 29 ms
10,752 KB
testcase_05 AC 30 ms
10,752 KB
testcase_06 AC 29 ms
10,880 KB
testcase_07 AC 29 ms
10,752 KB
testcase_08 AC 29 ms
10,880 KB
testcase_09 AC 29 ms
10,752 KB
testcase_10 AC 30 ms
10,752 KB
testcase_11 AC 29 ms
10,880 KB
testcase_12 AC 30 ms
10,752 KB
testcase_13 AC 48 ms
11,776 KB
testcase_14 AC 48 ms
11,904 KB
testcase_15 AC 47 ms
11,776 KB
testcase_16 AC 47 ms
11,776 KB
testcase_17 AC 47 ms
11,776 KB
testcase_18 AC 47 ms
11,904 KB
testcase_19 AC 47 ms
11,776 KB
testcase_20 AC 47 ms
11,776 KB
testcase_21 AC 46 ms
11,776 KB
testcase_22 AC 47 ms
11,776 KB
testcase_23 AC 391 ms
32,556 KB
testcase_24 AC 392 ms
32,396 KB
testcase_25 AC 383 ms
32,396 KB
testcase_26 AC 393 ms
32,560 KB
testcase_27 AC 387 ms
32,392 KB
testcase_28 AC 291 ms
32,556 KB
testcase_29 AC 291 ms
32,520 KB
testcase_30 AC 339 ms
32,396 KB
testcase_31 AC 329 ms
32,524 KB
testcase_32 AC 346 ms
32,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate

N = int(input())

A = list(map(int,input().split()))
l = list(accumulate(A, min))
r = list(accumulate(A[::-1], min))[::-1]
INF = 10**18
ans = INF

for i in range(1,N-1):
  a,b,c = l[i-1],A[i],r[i+1]
  if a <= b and c <= b:
    ans = min(ans,a+b+c)
  if a >= b and c >= b:
    ans = min(ans,a+b+c)

if ans == INF:
  print(-1)
else:
  print(ans)
0