結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー SSlimeSSlime
提出日時 2020-06-27 10:19:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 513 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 30,436 KB
最終ジャッジ日時 2023-09-18 19:11:53
合計ジャッジ時間 7,372 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,776 KB
testcase_01 AC 16 ms
7,996 KB
testcase_02 AC 15 ms
7,900 KB
testcase_03 AC 15 ms
7,904 KB
testcase_04 WA -
testcase_05 AC 15 ms
7,856 KB
testcase_06 AC 16 ms
7,864 KB
testcase_07 AC 16 ms
7,852 KB
testcase_08 WA -
testcase_09 AC 15 ms
7,864 KB
testcase_10 WA -
testcase_11 AC 16 ms
7,916 KB
testcase_12 WA -
testcase_13 AC 38 ms
9,608 KB
testcase_14 AC 39 ms
9,612 KB
testcase_15 WA -
testcase_16 AC 39 ms
9,704 KB
testcase_17 WA -
testcase_18 AC 39 ms
9,768 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 39 ms
9,568 KB
testcase_23 AC 581 ms
30,332 KB
testcase_24 AC 600 ms
30,236 KB
testcase_25 AC 600 ms
30,104 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 346 ms
30,196 KB
testcase_29 AC 339 ms
30,412 KB
testcase_30 AC 456 ms
29,968 KB
testcase_31 AC 462 ms
29,904 KB
testcase_32 AC 457 ms
30,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int, input().split()))

mod = 10**9 + 7

Rm = [[0]*n,[0]*n]
B = sorted(range(n),key = lambda x:A[x])
ans = 10**9
for b in B:
    left = Rm[0][b]
    right = Rm[1][b]
    if left*right > 0:
        ans = min(ans, left + right + A[b])
    idx = b
    while idx < n:
        if Rm[0][idx] != 0:break
        Rm[0][idx] = A[b]
        idx += 1
    idx = b
    while idx >= 0:
        if Rm[1][idx] != 0:break
        Rm[1][idx] = A[b]
        idx -= 1
print(ans if ans != 10**9 else -1)
0