結果

問題 No.703 ゴミ拾い Easy
ユーザー maspymaspy
提出日時 2020-03-25 14:42:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 443 ms / 1,500 ms
コード長 1,459 bytes
コンパイル時間 418 ms
コンパイル使用メモリ 86,944 KB
実行使用メモリ 174,472 KB
最終ジャッジ日時 2023-08-30 19:46:52
合計ジャッジ時間 15,752 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,624 KB
testcase_01 AC 92 ms
71,800 KB
testcase_02 AC 92 ms
71,780 KB
testcase_03 AC 106 ms
71,592 KB
testcase_04 AC 92 ms
71,596 KB
testcase_05 AC 91 ms
71,664 KB
testcase_06 AC 91 ms
71,440 KB
testcase_07 AC 92 ms
71,704 KB
testcase_08 AC 92 ms
71,336 KB
testcase_09 AC 90 ms
71,668 KB
testcase_10 AC 91 ms
71,644 KB
testcase_11 AC 90 ms
71,716 KB
testcase_12 AC 91 ms
71,580 KB
testcase_13 AC 91 ms
71,340 KB
testcase_14 AC 100 ms
76,780 KB
testcase_15 AC 99 ms
76,772 KB
testcase_16 AC 99 ms
76,664 KB
testcase_17 AC 102 ms
76,668 KB
testcase_18 AC 101 ms
76,768 KB
testcase_19 AC 99 ms
76,764 KB
testcase_20 AC 100 ms
76,780 KB
testcase_21 AC 100 ms
76,532 KB
testcase_22 AC 116 ms
76,536 KB
testcase_23 AC 98 ms
76,536 KB
testcase_24 AC 382 ms
173,456 KB
testcase_25 AC 433 ms
173,748 KB
testcase_26 AC 379 ms
173,420 KB
testcase_27 AC 372 ms
173,836 KB
testcase_28 AC 371 ms
173,956 KB
testcase_29 AC 372 ms
173,588 KB
testcase_30 AC 369 ms
173,940 KB
testcase_31 AC 367 ms
173,816 KB
testcase_32 AC 393 ms
174,004 KB
testcase_33 AC 372 ms
174,008 KB
testcase_34 AC 423 ms
174,280 KB
testcase_35 AC 410 ms
174,348 KB
testcase_36 AC 418 ms
173,980 KB
testcase_37 AC 414 ms
174,416 KB
testcase_38 AC 420 ms
174,472 KB
testcase_39 AC 407 ms
173,848 KB
testcase_40 AC 408 ms
174,204 KB
testcase_41 AC 443 ms
174,240 KB
testcase_42 AC 412 ms
174,456 KB
testcase_43 AC 413 ms
174,208 KB
testcase_44 AC 92 ms
71,716 KB
testcase_45 AC 92 ms
71,184 KB
testcase_46 AC 338 ms
171,440 KB
testcase_47 AC 357 ms
172,856 KB
testcase_48 AC 101 ms
76,808 KB
testcase_49 AC 101 ms
76,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque


class ConvexHullTrick:
    """
    f_i = a_ix + b_i とする。f_i の追加および、min_i f(x) の取得ができるデータ構造。
    ただし、傾き a_i は降順に追加されなければならない。
    また、クエリ x も昇順に実行されなければならない。
    """

    def __init__(self):
        self.funcs = deque()

    def add(self, a, b):
        funcs = self.funcs
        while len(funcs) >= 2:
            a1, b1 = funcs[-2]
            a2, b2 = funcs[-1]
            if (a2 - a1) * (b - b2) < (b2 - b1) * (a - a2):
                break
            funcs.pop()
        funcs.append((a, b))

    def query(self, x):
        funcs = self.funcs
        a, b = funcs[0]
        y = a * x + b
        while len(funcs) >= 2:
            a2, b2 = funcs[1]
            y2 = a2 * x + b2
            if y < y2:
                break
            y = y2
            funcs.popleft()
        return y


N = int(readline())
dp = [0] * (N + 1)
A = tuple(map(int, readline().split()))
X = tuple(map(int, readline().split()))
Y = tuple(map(int, readline().split()))
cht = ConvexHullTrick()
add = cht.add
query = cht.query

for i, (a, x, y) in enumerate(zip(A, X, Y), 1):
    add(-2 * x, x * x + y * y + dp[i - 1])
    dp[i] = query(a) + a * a

print(dp[-1])
0