結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,880 KB
testcase_01 AC 26 ms
11,008 KB
testcase_02 AC 27 ms
10,880 KB
testcase_03 AC 27 ms
11,008 KB
testcase_04 WA -
testcase_05 AC 25 ms
10,880 KB
testcase_06 AC 25 ms
11,008 KB
testcase_07 AC 26 ms
10,880 KB
testcase_08 WA -
testcase_09 AC 25 ms
10,880 KB
testcase_10 WA -
testcase_11 AC 26 ms
10,880 KB
testcase_12 WA -
testcase_13 AC 49 ms
12,288 KB
testcase_14 AC 50 ms
12,288 KB
testcase_15 WA -
testcase_16 AC 50 ms
12,288 KB
testcase_17 WA -
testcase_18 AC 49 ms
12,416 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 51 ms
12,288 KB
testcase_23 AC 548 ms
32,664 KB
testcase_24 AC 524 ms
32,504 KB
testcase_25 AC 544 ms
32,504 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 360 ms
32,672 KB
testcase_29 AC 377 ms
32,796 KB
testcase_30 AC 463 ms
32,632 KB
testcase_31 AC 458 ms
32,508 KB
testcase_32 AC 453 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 and lmin != rmin:
        ans = min(ans, lmin+m+rmin)
    if lmax > m and m < rmax and lmax != rmax:
        ans = min(ans, lmax+m+rmax)

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