結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー MineMine
提出日時 2020-08-30 16:39:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,072 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 32,628 KB
最終ジャッジ日時 2024-04-27 10:14:11
合計ジャッジ時間 8,433 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
11,008 KB
testcase_01 AC 33 ms
10,880 KB
testcase_02 AC 33 ms
11,008 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 WA -
testcase_05 AC 31 ms
11,008 KB
testcase_06 AC 31 ms
10,880 KB
testcase_07 AC 31 ms
10,880 KB
testcase_08 WA -
testcase_09 AC 33 ms
11,008 KB
testcase_10 WA -
testcase_11 AC 31 ms
11,008 KB
testcase_12 WA -
testcase_13 AC 58 ms
12,288 KB
testcase_14 AC 57 ms
12,288 KB
testcase_15 WA -
testcase_16 AC 60 ms
12,160 KB
testcase_17 WA -
testcase_18 AC 56 ms
12,160 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 57 ms
12,288 KB
testcase_23 AC 593 ms
32,496 KB
testcase_24 AC 584 ms
32,628 KB
testcase_25 AC 592 ms
32,500 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 404 ms
32,500 KB
testcase_29 AC 416 ms
32,624 KB
testcase_30 AC 502 ms
32,628 KB
testcase_31 AC 496 ms
32,500 KB
testcase_32 AC 491 ms
32,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

rminList = rminList[::-1]
rmaxList = rmaxList[::-1]

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

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

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