結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー hir355hir355
提出日時 2020-06-26 21:27:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 638 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 30,444 KB
最終ジャッジ日時 2023-09-18 03:00:37
合計ジャッジ時間 10,253 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,236 KB
testcase_01 AC 17 ms
8,224 KB
testcase_02 AC 16 ms
8,104 KB
testcase_03 AC 18 ms
8,212 KB
testcase_04 WA -
testcase_05 AC 17 ms
8,268 KB
testcase_06 AC 17 ms
8,192 KB
testcase_07 AC 17 ms
8,328 KB
testcase_08 WA -
testcase_09 AC 17 ms
8,172 KB
testcase_10 WA -
testcase_11 AC 17 ms
8,172 KB
testcase_12 WA -
testcase_13 AC 59 ms
9,512 KB
testcase_14 AC 57 ms
9,324 KB
testcase_15 WA -
testcase_16 AC 59 ms
9,416 KB
testcase_17 WA -
testcase_18 AC 58 ms
9,384 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 57 ms
9,352 KB
testcase_23 AC 831 ms
30,284 KB
testcase_24 AC 840 ms
30,008 KB
testcase_25 AC 837 ms
29,968 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 628 ms
30,380 KB
testcase_29 AC 627 ms
30,444 KB
testcase_30 AC 731 ms
30,064 KB
testcase_31 AC 732 ms
29,948 KB
testcase_32 AC 746 ms
29,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 9
n = int(input())
a = list(map(int, input().split()))
p = [INF] * (n + 1)
q = [INF] * (n + 1)
for i in range(n):
    p[i + 1] = min(p[i], a[i])
for i in range(n, 0, -1):
    q[i - 1] = min(q[i], a[i - 1])
ans = INF
for i in range(1, n):
    if max(p[i], q[i + 1]) < a[i]:
        ans = min(ans, p[i] + q[i + 1] + a[i])

p = [0] * (n + 1)
q = [0] * (n + 1)
for i in range(n):
    p[i + 1] = max(p[i], a[i])
for i in range(n, 0, -1):
    q[i - 1] = max(q[i], a[i - 1])
for i in range(1, n - 1):
    if min(p[i], q[i + 1]) > a[i]:
        ans = min(ans, p[i] + q[i + 1] + a[i])
if ans == INF:
    print(-1)
else:
    print(ans)
0