結果

問題 No.703 ゴミ拾い Easy
ユーザー ああいいああいい
提出日時 2022-03-10 00:13:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 400 ms / 1,500 ms
コード長 1,288 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 168,872 KB
最終ジャッジ日時 2023-10-12 01:50:41
合計ジャッジ時間 15,093 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,340 KB
testcase_01 AC 94 ms
71,412 KB
testcase_02 AC 92 ms
71,516 KB
testcase_03 AC 94 ms
71,256 KB
testcase_04 AC 95 ms
71,540 KB
testcase_05 AC 94 ms
71,232 KB
testcase_06 AC 95 ms
71,260 KB
testcase_07 AC 95 ms
71,320 KB
testcase_08 AC 96 ms
71,340 KB
testcase_09 AC 95 ms
71,340 KB
testcase_10 AC 99 ms
71,340 KB
testcase_11 AC 96 ms
71,180 KB
testcase_12 AC 96 ms
71,336 KB
testcase_13 AC 96 ms
71,456 KB
testcase_14 AC 109 ms
76,704 KB
testcase_15 AC 108 ms
76,764 KB
testcase_16 AC 106 ms
76,760 KB
testcase_17 AC 108 ms
76,828 KB
testcase_18 AC 109 ms
76,828 KB
testcase_19 AC 108 ms
76,912 KB
testcase_20 AC 107 ms
77,156 KB
testcase_21 AC 108 ms
76,812 KB
testcase_22 AC 109 ms
76,840 KB
testcase_23 AC 107 ms
76,832 KB
testcase_24 AC 390 ms
151,408 KB
testcase_25 AC 373 ms
151,064 KB
testcase_26 AC 370 ms
152,420 KB
testcase_27 AC 391 ms
151,208 KB
testcase_28 AC 383 ms
152,348 KB
testcase_29 AC 387 ms
150,988 KB
testcase_30 AC 384 ms
152,428 KB
testcase_31 AC 399 ms
152,708 KB
testcase_32 AC 375 ms
152,628 KB
testcase_33 AC 380 ms
151,392 KB
testcase_34 AC 400 ms
168,444 KB
testcase_35 AC 390 ms
167,464 KB
testcase_36 AC 352 ms
167,576 KB
testcase_37 AC 389 ms
167,828 KB
testcase_38 AC 349 ms
168,872 KB
testcase_39 AC 346 ms
167,528 KB
testcase_40 AC 393 ms
167,684 KB
testcase_41 AC 397 ms
167,480 KB
testcase_42 AC 390 ms
167,560 KB
testcase_43 AC 397 ms
167,500 KB
testcase_44 AC 95 ms
71,604 KB
testcase_45 AC 96 ms
71,456 KB
testcase_46 AC 310 ms
151,488 KB
testcase_47 AC 334 ms
147,844 KB
testcase_48 AC 107 ms
76,716 KB
testcase_49 AC 109 ms
76,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque


#Convex Hull Trick min ver
#a1 >= a2 >= a3 ...
#x1 <= x2 <= x3 ...  とする
#不等号逆にしたいときは、popとpopleft,deq[-1]とdeq[0]等を入れ替える か、
#a,x を逆順sortするか
#max ver は↓にある

class CHTmin:

    deq = deque()
    
    def check(self,f1,f2,f3):
        return (f2[0] - f1[0]) * (f3[1] - f2[1]) >= (f2[1]-f1[1]) * (f3[0]-f2[0])
    def f(self,f1,x):
        return f1[0] * x + f1[1]
    def add_line(self,a,b):
        f1 = (a,b)
        deq = self.deq
        if deq and deq[-1][0] == a:
            if deq[-1][1] > b:
                deq.pop()
        while len(deq) >= 2 and self.check(deq[-2],deq[-1],f1):
            deq.pop()
        deq.append(f1)
    def query(self,x):
        deq = self.deq
        while len(deq) >= 2 and self.f(deq[0],x) >= self.f(deq[1],x):
            deq.popleft()
        return self.f(deq[0],x)
import sys
n = int(input())
a = list(map(int,input().split()))
x = list(map(int,input().split()))
y = list(map(int,input().split()))
dp = [0] * n

cht = CHTmin()
cht.add_line(-2*x[0],x[0]**2+y[0]**2)

for i in range(n):
    tmp = cht.query(a[i])
    dp[i] = tmp + a[i] ** 2
    if i < n - 1:
        cht.add_line(-2 * x[i+1],dp[i] + x[i+1] ** 2 + y[i+1] ** 2)
print(dp[-1])
0