結果

問題 No.703 ゴミ拾い Easy
ユーザー ayaoniayaoni
提出日時 2021-08-14 03:37:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 640 ms / 1,500 ms
コード長 2,323 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 82,144 KB
実行使用メモリ 189,888 KB
最終ジャッジ日時 2024-04-15 01:14:07
合計ジャッジ時間 14,254 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,528 KB
testcase_01 AC 36 ms
53,420 KB
testcase_02 AC 35 ms
52,748 KB
testcase_03 AC 38 ms
53,732 KB
testcase_04 AC 39 ms
53,628 KB
testcase_05 AC 37 ms
53,728 KB
testcase_06 AC 37 ms
53,116 KB
testcase_07 AC 35 ms
53,372 KB
testcase_08 AC 36 ms
52,880 KB
testcase_09 AC 37 ms
53,372 KB
testcase_10 AC 36 ms
53,948 KB
testcase_11 AC 36 ms
53,084 KB
testcase_12 AC 36 ms
53,288 KB
testcase_13 AC 38 ms
53,840 KB
testcase_14 AC 76 ms
76,368 KB
testcase_15 AC 73 ms
76,368 KB
testcase_16 AC 73 ms
76,560 KB
testcase_17 AC 75 ms
76,492 KB
testcase_18 AC 77 ms
76,708 KB
testcase_19 AC 77 ms
76,864 KB
testcase_20 AC 78 ms
76,420 KB
testcase_21 AC 71 ms
76,304 KB
testcase_22 AC 77 ms
76,356 KB
testcase_23 AC 85 ms
76,900 KB
testcase_24 AC 640 ms
189,696 KB
testcase_25 AC 614 ms
189,176 KB
testcase_26 AC 602 ms
189,508 KB
testcase_27 AC 605 ms
189,080 KB
testcase_28 AC 622 ms
189,620 KB
testcase_29 AC 612 ms
188,880 KB
testcase_30 AC 609 ms
189,516 KB
testcase_31 AC 616 ms
189,876 KB
testcase_32 AC 598 ms
189,888 KB
testcase_33 AC 611 ms
189,776 KB
testcase_34 AC 268 ms
168,920 KB
testcase_35 AC 261 ms
168,860 KB
testcase_36 AC 265 ms
169,072 KB
testcase_37 AC 261 ms
168,572 KB
testcase_38 AC 261 ms
168,216 KB
testcase_39 AC 262 ms
168,820 KB
testcase_40 AC 263 ms
168,596 KB
testcase_41 AC 260 ms
168,820 KB
testcase_42 AC 261 ms
168,216 KB
testcase_43 AC 261 ms
168,392 KB
testcase_44 AC 35 ms
52,808 KB
testcase_45 AC 38 ms
53,580 KB
testcase_46 AC 249 ms
169,364 KB
testcase_47 AC 269 ms
164,960 KB
testcase_48 AC 78 ms
76,236 KB
testcase_49 AC 80 ms
76,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


class LiChao_tree():
    def __init__(self,X):  # Xに属する点における最小値を考える
        X = sorted(set(X))
        self.inf = 1 << 61
        self.N = 1 << (len(X)-1).bit_length()
        self.X = X+[self.inf]*(self.N-len(X))
        self.tree = [None]*(self.N << 1)
        self.X_dict = {x: i for i,x in enumerate(X)}

    def get_val(self,a,b,x):
        return a*x+b

    def add_line(self,a,b):  # 直線ax+bの追加
        i = 1
        left,right = 0,self.N
        while left < right:
            if self.tree[i] is None:
                self.tree[i] = (a,b)
                return
            mid = (left+right) >> 1
            x_left,x_mid,x_right = self.X[left],self.X[mid],self.X[right-1]
            ai,bi = self.tree[i]
            comp_left = self.get_val(a,b,x_left) < self.get_val(ai,bi,x_left)
            comp_mid = self.get_val(a,b,x_mid) < self.get_val(ai,bi,x_mid)
            comp_right = self.get_val(a,b,x_right) < self.get_val(ai,bi,x_right)

            if comp_left == comp_right:
                if comp_left:
                    self.tree[i] = (a,b)
                return
            if comp_mid:
                self.tree[i],a,b = (a,b),ai,bi
            if comp_left != comp_mid:
                i,right = i << 1,mid
            else:
                i,left = i << 1 | 1,mid

    def get_min(self,x):  # xにおける最小値を返す
        i = self.X_dict[x]+self.N
        res = self.inf
        while i:
            if self.tree[i] is not None:
                a,b = self.tree[i]
                res = min(res,self.get_val(a,b,x))
            i >>= 1
        return res


N = I()
A = [0]+LI()
X = [0]+LI()
Y = [0]+LI()

inf = 10**18
dp = [inf]*(N+1)
dp[0] = 0
LCT = LiChao_tree(A[1:])
for i in range(1,N+1):
    x,y = X[i],Y[i]
    LCT.add_line(-2*x,x**2+y**2+dp[i-1])
    a = A[i]
    dp[i] = a**2+LCT.get_min(a)

ans = dp[-1]
print(ans)
0