結果
問題 | No.1077 Noelちゃんと星々4 |
ユーザー | convexineq |
提出日時 | 2021-07-19 02:58:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 100 ms / 2,000 ms |
コード長 | 1,311 bytes |
コンパイル時間 | 335 ms |
コンパイル使用メモリ | 87,292 KB |
実行使用メモリ | 76,180 KB |
最終ジャッジ日時 | 2023-09-23 06:50:03 |
合計ジャッジ時間 | 3,718 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 78 ms
71,416 KB |
testcase_01 | AC | 77 ms
71,448 KB |
testcase_02 | AC | 92 ms
75,744 KB |
testcase_03 | AC | 100 ms
76,180 KB |
testcase_04 | AC | 85 ms
75,804 KB |
testcase_05 | AC | 80 ms
71,548 KB |
testcase_06 | AC | 86 ms
75,692 KB |
testcase_07 | AC | 88 ms
75,760 KB |
testcase_08 | AC | 85 ms
75,600 KB |
testcase_09 | AC | 81 ms
71,316 KB |
testcase_10 | AC | 95 ms
76,000 KB |
testcase_11 | AC | 91 ms
75,832 KB |
testcase_12 | AC | 89 ms
75,700 KB |
testcase_13 | AC | 81 ms
71,436 KB |
testcase_14 | AC | 99 ms
75,812 KB |
testcase_15 | AC | 88 ms
75,948 KB |
testcase_16 | AC | 86 ms
75,608 KB |
testcase_17 | AC | 88 ms
75,680 KB |
testcase_18 | AC | 97 ms
76,168 KB |
testcase_19 | AC | 80 ms
71,496 KB |
testcase_20 | AC | 78 ms
71,212 KB |
testcase_21 | AC | 99 ms
76,036 KB |
ソースコード
from heapq import * class slope_trick(): def __init__(self): self.L = [] #mapheap self.R = [] #minheap self.shiftL = self.shiftR = 0 self.min_f = 0 # 関数に max(0,x-a) を加算 def addR(self,a): a -= self.shiftL if self.L and -self.L[0] > a: self.min_f -= self.L[0] + a v = heappushpop(self.L,-a) heappush(self.R,-v) # 関数に max(-,a-x) を加算 def addL(self,a): a -= self.shiftR if self.R and a > self.R[0]: self.min_f += a - self.R[0] v = heappushpop(self.R,a) heappush(self.L,-v) # 関数に定数 a を加算 def addconst(self,a): self.min_f += a # 関数の累積 min をとる def reducemin(self): self.R = [] # 関数を右に a 平行移動する、つまり f(x) \mapsto f(x-a) とする def shift(self,a): self.shiftL += a self.shiftR += a # 関数の最小値を求める def getmin(self): return self.min_f ####################################################################### import sys readline = sys.stdin.readline n = int(readline()) *a, = map(int,readline().split()) st = slope_trick() for ai in a: st.reducemin() st.addL(ai) st.addR(ai) print(st.getmin())