結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー 👑 timitimi
提出日時 2020-10-02 16:48:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 697 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 12,612 KB
最終ジャッジ日時 2023-09-22 21:11:12
合計ジャッジ時間 8,591 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,612 KB
testcase_01 AC 16 ms
8,284 KB
testcase_02 AC 16 ms
8,324 KB
testcase_03 AC 17 ms
8,316 KB
testcase_04 AC 17 ms
8,408 KB
testcase_05 AC 17 ms
8,344 KB
testcase_06 AC 16 ms
8,248 KB
testcase_07 AC 17 ms
8,384 KB
testcase_08 AC 17 ms
8,360 KB
testcase_09 AC 17 ms
8,384 KB
testcase_10 AC 16 ms
8,356 KB
testcase_11 AC 17 ms
8,440 KB
testcase_12 AC 17 ms
8,412 KB
testcase_13 AC 378 ms
9,576 KB
testcase_14 AC 383 ms
9,676 KB
testcase_15 AC 376 ms
9,628 KB
testcase_16 AC 377 ms
9,572 KB
testcase_17 AC 376 ms
9,584 KB
testcase_18 AC 376 ms
9,668 KB
testcase_19 AC 380 ms
9,624 KB
testcase_20 AC 380 ms
9,624 KB
testcase_21 AC 380 ms
9,648 KB
testcase_22 AC 377 ms
9,696 KB
testcase_23 TLE -
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
import heapq
L=[]
R=sorted(A)
R.remove(A[0])
for i in range(1,N-1):
    heapq.heappush(L,A[i-1]) 
    R.remove(A[i])
    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