結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー hiragnhiragn
提出日時 2022-12-02 16:24:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 449 ms / 2,000 ms
コード長 629 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 32,588 KB
最終ジャッジ日時 2024-04-18 00:20:41
合計ジャッジ時間 7,337 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 32 ms
10,752 KB
testcase_03 AC 31 ms
10,624 KB
testcase_04 AC 31 ms
10,624 KB
testcase_05 AC 32 ms
10,624 KB
testcase_06 AC 31 ms
10,752 KB
testcase_07 AC 32 ms
10,752 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 32 ms
10,624 KB
testcase_10 AC 31 ms
10,624 KB
testcase_11 AC 31 ms
10,624 KB
testcase_12 AC 31 ms
10,752 KB
testcase_13 AC 51 ms
11,776 KB
testcase_14 AC 51 ms
11,776 KB
testcase_15 AC 51 ms
11,648 KB
testcase_16 AC 51 ms
11,776 KB
testcase_17 AC 51 ms
11,648 KB
testcase_18 AC 51 ms
11,776 KB
testcase_19 AC 51 ms
11,904 KB
testcase_20 AC 52 ms
11,776 KB
testcase_21 AC 51 ms
11,648 KB
testcase_22 AC 51 ms
11,776 KB
testcase_23 AC 443 ms
32,588 KB
testcase_24 AC 447 ms
32,296 KB
testcase_25 AC 444 ms
32,384 KB
testcase_26 AC 443 ms
32,456 KB
testcase_27 AC 449 ms
32,296 KB
testcase_28 AC 417 ms
32,468 KB
testcase_29 AC 412 ms
32,452 KB
testcase_30 AC 431 ms
32,292 KB
testcase_31 AC 428 ms
32,296 KB
testcase_32 AC 430 ms
32,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_kadomatsu(a, b, c):
    return len({a, b, c}) == 3 and (b > max(a, c) or b < min(a, c))


def main():
    n = int(input())
    a = list(map(int, input().split()))

    left = [a[0]] * n
    right = [a[-1]] * n
    for i in range(1, n):
        left[i] = min(left[i - 1], a[i])
    for i in reversed(range(n - 1)):
        right[i] = min(a[i], right[i + 1])

    ans = 10 ** 9
    for i in range(1, n - 1):
        if is_kadomatsu(left[i - 1], a[i], right[i + 1]):
            ans = min(ans, left[i - 1] + a[i] + right[i + 1])

    if ans == 10 ** 9:
        ans = -1
    print(ans)


if __name__ == "__main__":
    main()
0