結果

問題 No.409 ダイエット
ユーザー mkawa2mkawa2
提出日時 2023-02-07 11:17:50
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,411 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 86,692 KB
実行使用メモリ 120,980 KB
最終ジャッジ日時 2023-09-18 19:08:36
合計ジャッジ時間 14,760 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
71,576 KB
testcase_01 AC 98 ms
71,624 KB
testcase_02 AC 98 ms
71,476 KB
testcase_03 AC 102 ms
71,624 KB
testcase_04 AC 101 ms
71,476 KB
testcase_05 AC 100 ms
71,660 KB
testcase_06 AC 100 ms
71,648 KB
testcase_07 AC 98 ms
71,480 KB
testcase_08 AC 98 ms
71,652 KB
testcase_09 AC 98 ms
71,316 KB
testcase_10 AC 99 ms
71,692 KB
testcase_11 AC 99 ms
71,576 KB
testcase_12 AC 99 ms
71,564 KB
testcase_13 AC 99 ms
71,228 KB
testcase_14 AC 99 ms
71,656 KB
testcase_15 AC 100 ms
71,640 KB
testcase_16 AC 98 ms
71,588 KB
testcase_17 AC 99 ms
71,460 KB
testcase_18 AC 99 ms
71,236 KB
testcase_19 AC 100 ms
71,616 KB
testcase_20 AC 98 ms
71,476 KB
testcase_21 AC 97 ms
71,604 KB
testcase_22 AC 98 ms
71,576 KB
testcase_23 AC 98 ms
71,364 KB
testcase_24 AC 98 ms
71,688 KB
testcase_25 AC 99 ms
71,592 KB
testcase_26 AC 97 ms
71,652 KB
testcase_27 AC 101 ms
71,460 KB
testcase_28 AC 99 ms
71,520 KB
testcase_29 AC 99 ms
71,644 KB
testcase_30 AC 100 ms
71,668 KB
testcase_31 AC 97 ms
71,484 KB
testcase_32 AC 99 ms
71,500 KB
testcase_33 AC 99 ms
71,564 KB
testcase_34 AC 100 ms
71,624 KB
testcase_35 AC 156 ms
78,524 KB
testcase_36 AC 135 ms
77,712 KB
testcase_37 AC 131 ms
77,756 KB
testcase_38 AC 130 ms
77,856 KB
testcase_39 AC 132 ms
78,616 KB
testcase_40 AC 143 ms
78,528 KB
testcase_41 AC 129 ms
77,896 KB
testcase_42 AC 136 ms
78,344 KB
testcase_43 AC 129 ms
77,908 KB
testcase_44 AC 131 ms
77,856 KB
testcase_45 AC 132 ms
77,636 KB
testcase_46 AC 132 ms
78,340 KB
testcase_47 AC 136 ms
78,156 KB
testcase_48 AC 138 ms
78,176 KB
testcase_49 AC 123 ms
77,848 KB
testcase_50 AC 132 ms
78,372 KB
testcase_51 AC 128 ms
77,888 KB
testcase_52 AC 129 ms
78,416 KB
testcase_53 AC 133 ms
77,588 KB
testcase_54 AC 133 ms
77,852 KB
testcase_55 RE -
testcase_56 AC 174 ms
118,552 KB
testcase_57 AC 290 ms
118,916 KB
testcase_58 AC 228 ms
94,976 KB
testcase_59 AC 280 ms
103,420 KB
testcase_60 AC 224 ms
92,788 KB
testcase_61 AC 280 ms
114,048 KB
testcase_62 AC 289 ms
118,692 KB
testcase_63 AC 309 ms
114,388 KB
testcase_64 AC 265 ms
97,816 KB
testcase_65 AC 339 ms
114,384 KB
testcase_66 AC 316 ms
118,876 KB
testcase_67 RE -
testcase_68 AC 291 ms
103,160 KB
testcase_69 RE -
testcase_70 AC 294 ms
111,484 KB
testcase_71 AC 236 ms
95,596 KB
testcase_72 AC 307 ms
120,980 KB
testcase_73 AC 321 ms
116,284 KB
testcase_74 AC 237 ms
101,396 KB
testcase_75 AC 312 ms
116,980 KB
testcase_76 AC 254 ms
107,608 KB
testcase_77 AC 261 ms
95,860 KB
testcase_78 AC 228 ms
97,944 KB
testcase_79 AC 237 ms
93,376 KB
testcase_80 AC 295 ms
120,980 KB
testcase_81 AC 336 ms
116,992 KB
testcase_82 AC 274 ms
107,904 KB
testcase_83 AC 283 ms
107,800 KB
testcase_84 AC 280 ms
103,728 KB
testcase_85 AC 165 ms
79,248 KB
testcase_86 AC 293 ms
101,544 KB
testcase_87 AC 276 ms
111,644 KB
testcase_88 AC 230 ms
91,596 KB
testcase_89 AC 283 ms
107,508 KB
testcase_90 AC 229 ms
90,040 KB
testcase_91 AC 279 ms
110,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import abc
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

# 最小値、傾き単調減少、x単調増加
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
        # append
        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))
        # appendleft
        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):
        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, a, b, w = LI()
dd = LI()

cht = ConvexHullTrick()
cht.add_line(0, 2*w)

ans = w+n*(n+1)//2*b-a*n
for i, d in enumerate(dd):
    cur = (cht[i]+i*(b*(i+1)-2*a)+2*d)//2
    r = n-i-1
    ans = min(ans, cur+r*(r+1)//2*b-a*r)
    i += 1
    cht.add_line(-2*b*i, 2*cur+i*(b*(i-1)+2*a))

print(ans)
0