結果

問題 No.703 ゴミ拾い Easy
ユーザー ああいいああいい
提出日時 2022-03-09 23:55:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,338 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 168,804 KB
最終ジャッジ日時 2023-10-12 01:32:12
合計ジャッジ時間 14,496 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,292 KB
testcase_01 AC 94 ms
71,584 KB
testcase_02 AC 93 ms
71,528 KB
testcase_03 AC 94 ms
71,780 KB
testcase_04 AC 94 ms
71,600 KB
testcase_05 AC 101 ms
71,528 KB
testcase_06 WA -
testcase_07 AC 103 ms
71,744 KB
testcase_08 AC 93 ms
71,748 KB
testcase_09 AC 92 ms
71,788 KB
testcase_10 AC 94 ms
71,716 KB
testcase_11 AC 92 ms
71,652 KB
testcase_12 AC 92 ms
71,704 KB
testcase_13 AC 93 ms
71,556 KB
testcase_14 WA -
testcase_15 AC 106 ms
76,960 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 108 ms
77,032 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 282 ms
168,576 KB
testcase_35 AC 276 ms
167,516 KB
testcase_36 AC 266 ms
167,640 KB
testcase_37 AC 276 ms
167,576 KB
testcase_38 AC 269 ms
168,804 KB
testcase_39 AC 265 ms
167,388 KB
testcase_40 AC 275 ms
167,932 KB
testcase_41 AC 277 ms
167,496 KB
testcase_42 AC 275 ms
167,888 KB
testcase_43 AC 276 ms
167,776 KB
testcase_44 AC 92 ms
71,628 KB
testcase_45 AC 92 ms
71,620 KB
testcase_46 AC 262 ms
151,832 KB
testcase_47 AC 270 ms
147,960 KB
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます

ソースコード

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()
                deq.append(f1)
            return
        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