結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー H3PO4H3PO4
提出日時 2020-06-26 23:05:23
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 634 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 77,020 KB
最終ジャッジ日時 2024-07-04 23:31:22
合計ジャッジ時間 27,942 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

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