結果

問題 No.703 ゴミ拾い Easy
ユーザー ああいいああいい
提出日時 2022-03-10 00:11:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 360 ms / 1,500 ms
コード長 819 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 168,548 KB
最終ジャッジ日時 2023-10-12 01:49:00
合計ジャッジ時間 13,063 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,808 KB
testcase_01 AC 90 ms
71,696 KB
testcase_02 AC 90 ms
71,740 KB
testcase_03 AC 90 ms
71,692 KB
testcase_04 AC 90 ms
71,628 KB
testcase_05 AC 92 ms
71,684 KB
testcase_06 AC 91 ms
71,660 KB
testcase_07 AC 92 ms
71,676 KB
testcase_08 AC 90 ms
71,660 KB
testcase_09 AC 89 ms
71,680 KB
testcase_10 AC 93 ms
71,660 KB
testcase_11 AC 89 ms
71,788 KB
testcase_12 AC 90 ms
71,612 KB
testcase_13 AC 91 ms
71,848 KB
testcase_14 AC 103 ms
77,336 KB
testcase_15 AC 103 ms
77,300 KB
testcase_16 AC 102 ms
77,100 KB
testcase_17 AC 99 ms
77,076 KB
testcase_18 AC 101 ms
77,144 KB
testcase_19 AC 101 ms
77,196 KB
testcase_20 AC 100 ms
76,984 KB
testcase_21 AC 101 ms
76,816 KB
testcase_22 AC 103 ms
77,260 KB
testcase_23 AC 102 ms
76,812 KB
testcase_24 AC 318 ms
150,284 KB
testcase_25 AC 325 ms
151,316 KB
testcase_26 AC 330 ms
152,448 KB
testcase_27 AC 314 ms
150,864 KB
testcase_28 AC 323 ms
152,484 KB
testcase_29 AC 318 ms
151,164 KB
testcase_30 AC 329 ms
152,460 KB
testcase_31 AC 336 ms
153,008 KB
testcase_32 AC 316 ms
152,712 KB
testcase_33 AC 319 ms
151,316 KB
testcase_34 AC 351 ms
167,768 KB
testcase_35 AC 352 ms
167,856 KB
testcase_36 AC 321 ms
167,172 KB
testcase_37 AC 350 ms
167,832 KB
testcase_38 AC 318 ms
168,548 KB
testcase_39 AC 317 ms
167,308 KB
testcase_40 AC 350 ms
168,072 KB
testcase_41 AC 360 ms
167,692 KB
testcase_42 AC 353 ms
168,204 KB
testcase_43 AC 356 ms
167,588 KB
testcase_44 AC 87 ms
71,764 KB
testcase_45 AC 90 ms
71,252 KB
testcase_46 AC 286 ms
151,944 KB
testcase_47 AC 311 ms
148,612 KB
testcase_48 AC 103 ms
77,044 KB
testcase_49 AC 101 ms
76,772 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
add_line(-2 * x[0],x[0] ** 2 + y[0] ** 2)
for i in range(n):
    tmp = query(a[i])
    dp[i] = tmp + a[i] ** 2
    if i < n - 1:
        add_line(-2 * x[i+1],dp[i] + x[i+1] ** 2 + y[i+1] ** 2)
print(dp[-1])
0