結果

問題 No.703 ゴミ拾い Easy
コンテスト
ユーザー とりゐ
提出日時 2022-02-11 15:35:27
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 249 ms / 1,500 ms
コード長 709 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 419 ms
コンパイル使用メモリ 85,420 KB
実行使用メモリ 167,240 KB
最終ジャッジ日時 2026-03-15 00:25:46
合計ジャッジ時間 9,229 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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