結果

問題 No.703 ゴミ拾い Easy
ユーザー とりゐとりゐ
提出日時 2022-02-11 15:35:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 398 ms / 1,500 ms
コード長 709 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 168,388 KB
最終ジャッジ日時 2023-09-09 17:07:18
合計ジャッジ時間 17,583 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
71,644 KB
testcase_01 AC 101 ms
71,528 KB
testcase_02 AC 102 ms
71,676 KB
testcase_03 AC 102 ms
71,548 KB
testcase_04 AC 103 ms
71,784 KB
testcase_05 AC 102 ms
71,764 KB
testcase_06 AC 103 ms
71,644 KB
testcase_07 AC 104 ms
71,728 KB
testcase_08 AC 103 ms
71,596 KB
testcase_09 AC 103 ms
71,740 KB
testcase_10 AC 103 ms
71,484 KB
testcase_11 AC 103 ms
71,528 KB
testcase_12 AC 105 ms
71,616 KB
testcase_13 AC 104 ms
71,556 KB
testcase_14 AC 116 ms
77,220 KB
testcase_15 AC 113 ms
77,164 KB
testcase_16 AC 114 ms
77,180 KB
testcase_17 AC 116 ms
76,852 KB
testcase_18 AC 118 ms
76,980 KB
testcase_19 AC 116 ms
76,960 KB
testcase_20 AC 116 ms
77,072 KB
testcase_21 AC 116 ms
77,100 KB
testcase_22 AC 115 ms
76,952 KB
testcase_23 AC 115 ms
77,128 KB
testcase_24 AC 356 ms
150,976 KB
testcase_25 AC 377 ms
151,288 KB
testcase_26 AC 353 ms
152,284 KB
testcase_27 AC 366 ms
151,104 KB
testcase_28 AC 360 ms
152,660 KB
testcase_29 AC 341 ms
151,016 KB
testcase_30 AC 344 ms
151,468 KB
testcase_31 AC 351 ms
152,808 KB
testcase_32 AC 343 ms
151,192 KB
testcase_33 AC 344 ms
151,132 KB
testcase_34 AC 372 ms
167,956 KB
testcase_35 AC 398 ms
167,416 KB
testcase_36 AC 340 ms
167,496 KB
testcase_37 AC 358 ms
167,448 KB
testcase_38 AC 358 ms
168,388 KB
testcase_39 AC 358 ms
167,264 KB
testcase_40 AC 344 ms
167,400 KB
testcase_41 AC 359 ms
167,688 KB
testcase_42 AC 361 ms
168,132 KB
testcase_43 AC 353 ms
167,340 KB
testcase_44 AC 94 ms
71,644 KB
testcase_45 AC 95 ms
71,600 KB
testcase_46 AC 309 ms
151,884 KB
testcase_47 AC 318 ms
148,528 KB
testcase_48 AC 107 ms
76,980 KB
testcase_49 AC 106 ms
76,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
deq = deque()
def check(f1, f2, f3):
    return (f2[0] - f1[0]) * (f3[1] - f2[1]) >= (f2[1] - f1[1]) * (f3[0] - f2[0])
def f(f1, x):
    return f1[0]*x + f1[1]

# add f_i(x) = a*x + b
def add_line(a, b):
    f1 = (a, b)
    while len(deq) >= 2 and check(deq[-2], deq[-1], f1):
        deq.pop()
    deq.append(f1)

# min f_i(x)
def query(x):
    while len(deq) >= 2 and f(deq[0], x) >= f(deq[1], x):
        deq.popleft()
    return f(deq[0], x)

n=int(input())
a=list(map(int,input().split()))
x=list(map(int,input().split()))
y=list(map(int,input().split()))

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