結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー uni_pythonuni_python
提出日時 2020-06-26 21:32:09
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,204 bytes
コンパイル時間 1,101 ms
コンパイル使用メモリ 86,600 KB
実行使用メモリ 106,460 KB
最終ジャッジ日時 2023-09-18 03:12:07
合計ジャッジ時間 5,918 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,204 KB
testcase_01 AC 69 ms
70,980 KB
testcase_02 AC 69 ms
71,208 KB
testcase_03 AC 68 ms
71,064 KB
testcase_04 WA -
testcase_05 AC 70 ms
71,256 KB
testcase_06 AC 70 ms
71,452 KB
testcase_07 AC 69 ms
71,248 KB
testcase_08 WA -
testcase_09 AC 69 ms
71,452 KB
testcase_10 WA -
testcase_11 AC 68 ms
71,120 KB
testcase_12 WA -
testcase_13 AC 83 ms
76,160 KB
testcase_14 AC 82 ms
76,420 KB
testcase_15 WA -
testcase_16 AC 82 ms
76,356 KB
testcase_17 WA -
testcase_18 AC 82 ms
76,260 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 84 ms
76,228 KB
testcase_23 AC 137 ms
106,004 KB
testcase_24 AC 141 ms
106,460 KB
testcase_25 AC 135 ms
106,336 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 131 ms
105,996 KB
testcase_29 AC 133 ms
106,128 KB
testcase_30 AC 143 ms
106,404 KB
testcase_31 AC 143 ms
106,180 KB
testcase_32 AC 146 ms
106,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    inf=10**9
    ml=[inf]*N
    mr=[inf]*N
    
    m=inf
    for i in range(N):
        ml[i]=m
        if A[i]<m:
            m=A[i]
        
    m=inf
    for i in range(N-1,-1,-1):
        mr[i]=m
        if A[i]<m:
            m=A[i]
        
    ans=inf
    for i in range(N):
        if ml[i]<A[i] and mr[i]<A[i]:
            temp=ml[i]+mr[i]+A[i]
            ans=min(ans,temp)
            
    ###################
    
    for i in range(N):
        A[i]*=-1        
    inf=-1*(10**9)
    ml=[inf]*N
    mr=[inf]*N
    
    m=inf
    for i in range(N):
        ml[i]=m
        if A[i]>m:
            m=A[i]
        
    m=inf
    for i in range(N-1,-1,-1):
        mr[i]=m
        if A[i]>m:
            m=A[i]
        
    ans2=inf
    for i in range(N):
        if ml[i]>A[i] and mr[i]>A[i]:
            temp=ml[i]+mr[i]+A[i]
            ans2=max(ans2,temp)
            
    ans2*=-1
    ans=min(ans,ans2)
    inf=10**9
    
    if ans>=inf:
        ans=-1
    print(ans)
    


main()
0