結果

問題 No.1435 Mmm......
ユーザー titiatitia
提出日時 2021-03-20 00:20:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,244 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 59,452 KB
最終ジャッジ日時 2024-04-29 20:20:46
合計ジャッジ時間 28,263 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
16,128 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 33 ms
10,752 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 31 ms
10,880 KB
testcase_06 AC 1,240 ms
22,800 KB
testcase_07 AC 1,509 ms
25,384 KB
testcase_08 AC 1,750 ms
27,652 KB
testcase_09 AC 1,598 ms
26,280 KB
testcase_10 AC 1,388 ms
24,180 KB
testcase_11 AC 1,383 ms
24,032 KB
testcase_12 AC 1,272 ms
23,180 KB
testcase_13 AC 1,259 ms
23,268 KB
testcase_14 AC 950 ms
20,148 KB
testcase_15 AC 1,812 ms
28,364 KB
testcase_16 AC 1,495 ms
25,492 KB
testcase_17 AC 1,068 ms
21,700 KB
testcase_18 AC 1,819 ms
28,604 KB
testcase_19 AC 1,342 ms
24,080 KB
testcase_20 AC 1,655 ms
27,140 KB
testcase_21 TLE -
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
import heapq

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

MIN=[]

heapq.heappush(MIN,(A[0],0))
heapq.heappush(MIN,(A[1],1))

MAX=[]
heapq.heappush(MAX,(-A[0],0))
heapq.heappush(MAX,(-A[1],1))


ANS=0
now=1
for i in range(N):
    #print(i,now)
    
    while True:
        if now==N:
            ANS+=now-i-1
            break
        
        
        while MIN[0][1]<i:
            heapq.heappop(MIN)
        x,xi=heapq.heappop(MIN)

        while MIN[0][1]<i:
            heapq.heappop(MIN)
        y,yi=heapq.heappop(MIN)

        k=x+y

        while MAX[0][1]<i:
            heapq.heappop(MAX)

        l,li=heapq.heappop(MAX)

        if -l>k:
            ANS+=now-i-1
            heapq.heappush(MIN,(x,xi))
            heapq.heappush(MIN,(y,yi))
            heapq.heappush(MAX,(l,li))
            break
        else:
            now+=1
            heapq.heappush(MIN,(x,xi))
            heapq.heappush(MIN,(y,yi))
            heapq.heappush(MAX,(l,li))

            if now==N:
                continue

            heapq.heappush(MIN,(A[now],now))
            heapq.heappush(MAX,(-A[now],now))
            
    #print(i,now,k,l,MIN,MAX)

print(ANS)

            
        

    

    
    
    
0