結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー H3PO4H3PO4
提出日時 2020-06-26 23:05:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 634 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 10,828 KB
実行使用メモリ 64,168 KB
最終ジャッジ日時 2023-09-18 07:21:05
合計ジャッジ時間 15,295 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
29,624 KB
testcase_01 AC 140 ms
29,612 KB
testcase_02 AC 138 ms
29,672 KB
testcase_03 AC 139 ms
29,728 KB
testcase_04 WA -
testcase_05 AC 137 ms
29,728 KB
testcase_06 AC 137 ms
29,704 KB
testcase_07 AC 135 ms
29,612 KB
testcase_08 WA -
testcase_09 AC 135 ms
29,648 KB
testcase_10 WA -
testcase_11 AC 134 ms
29,772 KB
testcase_12 WA -
testcase_13 AC 173 ms
31,080 KB
testcase_14 AC 165 ms
31,040 KB
testcase_15 WA -
testcase_16 AC 164 ms
31,032 KB
testcase_17 WA -
testcase_18 AC 166 ms
30,996 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 163 ms
31,072 KB
testcase_23 AC 778 ms
64,132 KB
testcase_24 AC 787 ms
57,580 KB
testcase_25 AC 808 ms
64,168 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 405 ms
57,832 KB
testcase_29 AC 399 ms
57,752 KB
testcase_30 AC 611 ms
63,884 KB
testcase_31 AC 606 ms
57,612 KB
testcase_32 AC 596 ms
57,904 KB
権限があれば一括ダウンロードができます

ソースコード

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