結果

問題 No.703 ゴミ拾い Easy
ユーザー mkawa2mkawa2
提出日時 2023-02-28 13:32:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 461 ms / 1,500 ms
コード長 3,265 bytes
コンパイル時間 1,488 ms
コンパイル使用メモリ 85,704 KB
実行使用メモリ 164,044 KB
最終ジャッジ日時 2023-10-13 20:02:01
合計ジャッジ時間 18,817 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,768 KB
testcase_01 AC 98 ms
71,804 KB
testcase_02 AC 97 ms
71,644 KB
testcase_03 AC 95 ms
71,552 KB
testcase_04 AC 98 ms
71,540 KB
testcase_05 AC 98 ms
71,516 KB
testcase_06 AC 95 ms
71,744 KB
testcase_07 AC 94 ms
71,520 KB
testcase_08 AC 96 ms
71,500 KB
testcase_09 AC 95 ms
71,840 KB
testcase_10 AC 96 ms
71,612 KB
testcase_11 AC 93 ms
71,764 KB
testcase_12 AC 94 ms
71,700 KB
testcase_13 AC 94 ms
71,344 KB
testcase_14 AC 104 ms
76,708 KB
testcase_15 AC 106 ms
76,828 KB
testcase_16 AC 105 ms
76,620 KB
testcase_17 AC 105 ms
76,888 KB
testcase_18 AC 104 ms
76,560 KB
testcase_19 AC 106 ms
76,664 KB
testcase_20 AC 105 ms
76,680 KB
testcase_21 AC 106 ms
76,668 KB
testcase_22 AC 104 ms
76,728 KB
testcase_23 AC 105 ms
76,628 KB
testcase_24 AC 458 ms
144,568 KB
testcase_25 AC 461 ms
145,552 KB
testcase_26 AC 422 ms
145,988 KB
testcase_27 AC 427 ms
145,732 KB
testcase_28 AC 425 ms
145,904 KB
testcase_29 AC 426 ms
145,524 KB
testcase_30 AC 418 ms
146,444 KB
testcase_31 AC 419 ms
145,852 KB
testcase_32 AC 437 ms
145,960 KB
testcase_33 AC 421 ms
145,748 KB
testcase_34 AC 306 ms
162,788 KB
testcase_35 AC 302 ms
162,836 KB
testcase_36 AC 305 ms
162,556 KB
testcase_37 AC 309 ms
162,776 KB
testcase_38 AC 307 ms
164,044 KB
testcase_39 AC 301 ms
162,528 KB
testcase_40 AC 310 ms
162,888 KB
testcase_41 AC 302 ms
162,616 KB
testcase_42 AC 309 ms
162,740 KB
testcase_43 AC 307 ms
163,000 KB
testcase_44 AC 95 ms
71,676 KB
testcase_45 AC 94 ms
71,748 KB
testcase_46 AC 285 ms
144,708 KB
testcase_47 AC 299 ms
142,580 KB
testcase_48 AC 105 ms
76,832 KB
testcase_49 AC 106 ms
76,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
md = 10**9+7
# md = 998244353

from collections import deque

class ConvexHullTrick:
    def __init__(self, getmin=1, a_inc=0, x_inc=1):
        self._getmin = getmin
        self._a_inc = a_inc
        self._x_inc = x_inc
        self._ab = deque()
        self._inf = (1 << 63)-1
        self._px = self._inf*(-2*x_inc+1)

    def add_line(self, a, b):
        if not self._ab:
            self._ab.append((a, b))
            return
        if self._getmin ^ self._a_inc:
            if self._ab and a == self._ab[-1][0]:
                if (b-self._ab[-1][1])*(self._getmin*2-1) >= 0: return
                self._ab.pop()
            if self._x_inc:
                while len(self._ab) > 1:
                    c, d = self._ab.pop()
                    e, f = self._ab[-1]
                    if (b-d)*(e-c) > (d-f)*(c-a):
                        self._ab.append((c, d))
                        break
            else:
                (c, d), x = self._ab[-1], self._px
                if (a*x+b-c*x-d)*(self._getmin*2-1) >= 0: return
            self._ab.append((a, b))
        else:
            if self._ab and a == self._ab[0][0]:
                if (b-self._ab[0][1])*(self._getmin*2-1) >= 0: return
                self._ab.popleft()
            if not self._x_inc:
                while len(self._ab) > 1:
                    c, d = self._ab.popleft()
                    e, f = self._ab[0]
                    if (b-d)*(e-c) < (d-f)*(c-a):
                        self._ab.append((c, d))
                        break
            else:
                (c, d), x = self._ab[0], self._px
                if (a*x+b-c*x-d)*(self._getmin*2-1) >= 0: return
            self._ab.appendleft((a, b))

    def __getitem__(self, x):
        self._px = x
        if not self._ab: return self._inf*(self._getmin*2-1)
        if self._x_inc:
            while len(self._ab) > 1:
                a, b = self._ab.popleft()
                c, d = self._ab[0]
                if (a*x+b-c*x-d)*(self._getmin*2-1) < 0:
                    self._ab.appendleft((a, b))
                    return a*x+b
        else:
            while len(self._ab) > 1:
                a, b = self._ab.pop()
                c, d = self._ab[-1]
                if (a*x+b-c*x-d)*(self._getmin*2-1) < 0:
                    self._ab.append((a, b))
                    return a*x+b
        a, b = self._ab[0]
        return a*x+b

n = II()
aa = LI()
xx = LI()
yy = LI()

cht = ConvexHullTrick()
mn = 0
for a, x, y in zip(aa, xx, yy):
    cht.add_line(-2*x, x**2+y**2+mn)
    mn = a**2+cht[a]

print(mn)
0