結果

問題 No.409 ダイエット
ユーザー mkawa2mkawa2
提出日時 2023-02-06 23:39:58
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,866 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 121,304 KB
最終ジャッジ日時 2023-09-18 09:13:54
合計ジャッジ時間 20,085 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,360 KB
testcase_01 AC 92 ms
71,764 KB
testcase_02 AC 93 ms
71,516 KB
testcase_03 AC 93 ms
71,832 KB
testcase_04 AC 93 ms
71,828 KB
testcase_05 AC 93 ms
71,356 KB
testcase_06 AC 93 ms
71,528 KB
testcase_07 AC 92 ms
71,636 KB
testcase_08 AC 92 ms
71,792 KB
testcase_09 AC 91 ms
71,824 KB
testcase_10 AC 92 ms
71,724 KB
testcase_11 AC 93 ms
71,764 KB
testcase_12 AC 92 ms
71,896 KB
testcase_13 AC 94 ms
71,716 KB
testcase_14 AC 94 ms
71,504 KB
testcase_15 AC 94 ms
71,636 KB
testcase_16 AC 94 ms
71,472 KB
testcase_17 AC 94 ms
71,504 KB
testcase_18 AC 94 ms
71,832 KB
testcase_19 AC 92 ms
71,512 KB
testcase_20 AC 91 ms
71,900 KB
testcase_21 AC 94 ms
71,604 KB
testcase_22 AC 94 ms
71,724 KB
testcase_23 AC 92 ms
71,628 KB
testcase_24 AC 94 ms
71,728 KB
testcase_25 AC 93 ms
71,364 KB
testcase_26 AC 92 ms
71,628 KB
testcase_27 AC 91 ms
71,836 KB
testcase_28 AC 92 ms
71,788 KB
testcase_29 AC 91 ms
71,640 KB
testcase_30 AC 91 ms
71,740 KB
testcase_31 AC 92 ms
71,512 KB
testcase_32 AC 93 ms
71,716 KB
testcase_33 AC 93 ms
71,496 KB
testcase_34 AC 93 ms
71,564 KB
testcase_35 AC 125 ms
78,188 KB
testcase_36 AC 125 ms
77,936 KB
testcase_37 AC 122 ms
77,956 KB
testcase_38 AC 122 ms
78,204 KB
testcase_39 AC 124 ms
78,484 KB
testcase_40 AC 129 ms
78,708 KB
testcase_41 AC 117 ms
77,932 KB
testcase_42 AC 126 ms
78,696 KB
testcase_43 AC 128 ms
78,000 KB
testcase_44 AC 120 ms
78,132 KB
testcase_45 AC 127 ms
78,160 KB
testcase_46 AC 124 ms
78,500 KB
testcase_47 AC 128 ms
78,208 KB
testcase_48 AC 131 ms
78,728 KB
testcase_49 AC 116 ms
77,904 KB
testcase_50 AC 127 ms
78,692 KB
testcase_51 AC 121 ms
78,024 KB
testcase_52 AC 121 ms
78,664 KB
testcase_53 AC 128 ms
78,100 KB
testcase_54 AC 128 ms
78,148 KB
testcase_55 RE -
testcase_56 AC 160 ms
118,452 KB
testcase_57 AC 267 ms
119,228 KB
testcase_58 AC 207 ms
94,676 KB
testcase_59 AC 251 ms
103,112 KB
testcase_60 AC 202 ms
92,592 KB
testcase_61 AC 255 ms
114,376 KB
testcase_62 AC 254 ms
119,156 KB
testcase_63 AC 274 ms
114,336 KB
testcase_64 AC 230 ms
97,692 KB
testcase_65 AC 299 ms
114,060 KB
testcase_66 AC 279 ms
119,032 KB
testcase_67 RE -
testcase_68 AC 261 ms
103,368 KB
testcase_69 RE -
testcase_70 AC 270 ms
111,596 KB
testcase_71 AC 210 ms
95,696 KB
testcase_72 AC 277 ms
121,304 KB
testcase_73 AC 302 ms
116,348 KB
testcase_74 AC 221 ms
101,580 KB
testcase_75 AC 285 ms
116,424 KB
testcase_76 AC 237 ms
107,572 KB
testcase_77 AC 233 ms
95,512 KB
testcase_78 AC 207 ms
98,152 KB
testcase_79 AC 216 ms
93,468 KB
testcase_80 AC 269 ms
120,780 KB
testcase_81 AC 301 ms
116,444 KB
testcase_82 AC 246 ms
107,564 KB
testcase_83 AC 258 ms
108,088 KB
testcase_84 AC 256 ms
104,084 KB
testcase_85 AC 154 ms
79,024 KB
testcase_86 AC 265 ms
101,764 KB
testcase_87 AC 256 ms
111,832 KB
testcase_88 AC 211 ms
92,172 KB
testcase_89 AC 258 ms
107,568 KB
testcase_90 AC 206 ms
89,768 KB
testcase_91 AC 253 ms
110,960 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

# 最小値、傾き単調減少、x単調増加
class ConvexHullTrick:
    def __init__(self):
        self.ab = deque()

    def add_line(self, a, b):
        if self.ab and a == self.ab[-1][0]:
            if b >= self.ab[-1][1]: return
            self.ab.pop()
        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
        self.ab.append((a, b))

    def min(self, x):
        if not self.ab: return (1 << 63)-1
        while len(self.ab) > 1:
            a, b = self.ab.popleft()
            c, d = self.ab[0]
            if a*x+b < c*x+d:
                self.ab.appendleft((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.min(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