結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー 👑 timitimi
提出日時 2020-10-02 16:43:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 646 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 10,792 KB
実行使用メモリ 14,160 KB
最終ジャッジ日時 2023-09-22 21:04:26
合計ジャッジ時間 5,935 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
12,628 KB
testcase_01 AC 16 ms
8,176 KB
testcase_02 AC 16 ms
8,248 KB
testcase_03 AC 16 ms
8,280 KB
testcase_04 AC 16 ms
8,180 KB
testcase_05 AC 15 ms
8,252 KB
testcase_06 AC 16 ms
8,232 KB
testcase_07 AC 16 ms
8,272 KB
testcase_08 AC 16 ms
8,272 KB
testcase_09 AC 16 ms
8,284 KB
testcase_10 AC 19 ms
8,264 KB
testcase_11 AC 17 ms
8,220 KB
testcase_12 AC 17 ms
8,220 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
A=list(map(int, input().split()))
LMI=[0 for i in range(N)]
RMI=[0 for i in range(N)]
mi,ma=10**9,0
for i in range(N):
    mi=min(A[i],mi)
    LMI[i]=mi
    
mi,ma=10**9,0
for i in range(N):
    mi=min(A[-1-i],mi)
    RMI[-1-i]=mi
ans=10**9
for i in range(1,N-1):
    if LMI[i-1]<A[i] and A[i]>RMI[i+1]:
        d=LMI[i-1]+A[i]+RMI[i+1]
        ans=min(d,ans)
import bisect

for i in range(1,N-1):
    L=sorted(A[:i])
    R=sorted(A[i+1:])
    a=bisect.bisect_right(L,A[i])
    b=bisect.bisect_right(R,A[i])
    if a!=i and b!=N-i-1:
        d=L[a]+A[i]+R[b]
        ans=min(d,ans)
if ans==10**9:
    print(-1)
else:
    print(ans)
0