結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー MineMine
提出日時 2020-08-30 17:23:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 372 ms / 2,000 ms
コード長 673 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 32,556 KB
最終ジャッジ日時 2024-04-27 11:51:55
合計ジャッジ時間 5,814 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
10,752 KB
testcase_01 AC 35 ms
10,752 KB
testcase_02 AC 32 ms
10,880 KB
testcase_03 AC 32 ms
10,752 KB
testcase_04 AC 32 ms
10,752 KB
testcase_05 AC 31 ms
10,752 KB
testcase_06 AC 32 ms
10,752 KB
testcase_07 AC 31 ms
10,752 KB
testcase_08 AC 31 ms
10,880 KB
testcase_09 AC 31 ms
10,880 KB
testcase_10 AC 31 ms
10,752 KB
testcase_11 AC 32 ms
10,880 KB
testcase_12 AC 30 ms
10,752 KB
testcase_13 AC 47 ms
11,904 KB
testcase_14 AC 47 ms
12,032 KB
testcase_15 AC 46 ms
11,904 KB
testcase_16 AC 46 ms
12,032 KB
testcase_17 AC 46 ms
12,032 KB
testcase_18 AC 47 ms
12,032 KB
testcase_19 AC 47 ms
11,904 KB
testcase_20 AC 46 ms
11,904 KB
testcase_21 AC 47 ms
11,904 KB
testcase_22 AC 46 ms
12,032 KB
testcase_23 AC 359 ms
32,432 KB
testcase_24 AC 355 ms
32,432 KB
testcase_25 AC 372 ms
32,436 KB
testcase_26 AC 359 ms
32,428 KB
testcase_27 AC 363 ms
32,428 KB
testcase_28 AC 292 ms
32,428 KB
testcase_29 AC 287 ms
32,428 KB
testcase_30 AC 321 ms
32,432 KB
testcase_31 AC 327 ms
32,428 KB
testcase_32 AC 317 ms
32,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int, input().split()))
lminList = [a[0]]
rminList = [a[-1]]
lmin = a[0]
rmin = a[-1]

for i in range(1, n):
    if  lmin > a[i]:
        lminList.append(a[i])
        lmin = a[i]
    else:
        lminList.append(lmin)

for i in range(n-1)[::-1]:
    if  rmin > a[i]:
        rminList.append(a[i])
        rmin = a[i]
    else:
        rminList.append(rmin)

rminList = rminList[::-1]

ans = float("inf")
for i in range(1, n-1):
    lmin = lminList[i-1]
    rmin = rminList[i+1]
    m = a[i]

    if lmin < m and m > rmin or lmin > m and m < rmin:
        ans = min(ans, lmin+m+rmin)

if ans == float("inf"):
    print(-1)
else:
    print(ans)
0