結果

問題 No.1095 Smallest Kadomatsu Subsequence
コンテスト
ユーザー H3PO4
提出日時 2020-06-26 23:05:23
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 634 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 687 ms
コンパイル使用メモリ 20,572 KB
実行使用メモリ 68,632 KB
最終ジャッジ日時 2026-03-26 05:59:37
合計ジャッジ時間 25,842 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))

L_min_Acc = np.minimum.accumulate(A).tolist()
R_min_Acc = np.minimum.accumulate(A[::-1])[::-1].tolist()
L_max_Acc = np.maximum.accumulate(A).tolist()
R_max_Acc = np.maximum.accumulate(A[::-1])[::-1].tolist()

ans = float('inf')
for i in range(1, N - 1):
    if A[i] > L_min_Acc[i - 1] and A[i] > R_min_Acc[i + 1]:
        ans = min(ans, L_min_Acc[i - 1] + A[i] + R_min_Acc[i + 1])
    if A[i] < L_max_Acc[i - 1] and A[i] < R_max_Acc[i + 1]:
        ans = min(ans, L_max_Acc[i - 1] + A[i] + R_max_Acc[i + 1])
print(ans if ans != float('inf') else -1)
0