結果

問題 No.409 ダイエット
ユーザー mkawa2mkawa2
提出日時 2023-02-08 00:10:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 789 ms / 2,000 ms
コード長 2,758 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 195,344 KB
最終ジャッジ日時 2024-07-05 17:25:41
合計ジャッジ時間 26,252 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,096 KB
testcase_01 AC 45 ms
52,352 KB
testcase_02 AC 43 ms
52,480 KB
testcase_03 AC 39 ms
52,224 KB
testcase_04 AC 40 ms
52,608 KB
testcase_05 AC 43 ms
52,736 KB
testcase_06 AC 40 ms
52,480 KB
testcase_07 AC 40 ms
52,736 KB
testcase_08 AC 40 ms
52,608 KB
testcase_09 AC 43 ms
52,608 KB
testcase_10 AC 40 ms
52,224 KB
testcase_11 AC 42 ms
52,608 KB
testcase_12 AC 44 ms
52,608 KB
testcase_13 AC 42 ms
52,736 KB
testcase_14 AC 42 ms
52,096 KB
testcase_15 AC 41 ms
52,608 KB
testcase_16 AC 42 ms
52,224 KB
testcase_17 AC 40 ms
52,736 KB
testcase_18 AC 41 ms
52,480 KB
testcase_19 AC 41 ms
52,608 KB
testcase_20 AC 41 ms
52,736 KB
testcase_21 AC 41 ms
52,096 KB
testcase_22 AC 41 ms
52,096 KB
testcase_23 AC 41 ms
52,224 KB
testcase_24 AC 41 ms
52,352 KB
testcase_25 AC 41 ms
52,736 KB
testcase_26 AC 41 ms
52,736 KB
testcase_27 AC 42 ms
52,608 KB
testcase_28 AC 42 ms
52,736 KB
testcase_29 AC 42 ms
52,352 KB
testcase_30 AC 41 ms
52,480 KB
testcase_31 AC 41 ms
52,480 KB
testcase_32 AC 41 ms
52,352 KB
testcase_33 AC 41 ms
52,480 KB
testcase_34 AC 42 ms
52,480 KB
testcase_35 AC 101 ms
76,928 KB
testcase_36 AC 104 ms
77,400 KB
testcase_37 AC 103 ms
77,104 KB
testcase_38 AC 105 ms
77,184 KB
testcase_39 AC 103 ms
76,996 KB
testcase_40 AC 110 ms
77,204 KB
testcase_41 AC 103 ms
77,136 KB
testcase_42 AC 106 ms
77,036 KB
testcase_43 AC 104 ms
77,648 KB
testcase_44 AC 103 ms
77,056 KB
testcase_45 AC 105 ms
77,028 KB
testcase_46 AC 106 ms
77,008 KB
testcase_47 AC 113 ms
76,908 KB
testcase_48 AC 108 ms
77,312 KB
testcase_49 AC 106 ms
77,184 KB
testcase_50 AC 107 ms
76,948 KB
testcase_51 AC 106 ms
77,160 KB
testcase_52 AC 107 ms
77,156 KB
testcase_53 AC 106 ms
76,996 KB
testcase_54 AC 104 ms
77,076 KB
testcase_55 AC 421 ms
136,448 KB
testcase_56 AC 330 ms
166,548 KB
testcase_57 AC 762 ms
166,972 KB
testcase_58 AC 372 ms
123,264 KB
testcase_59 AC 493 ms
139,520 KB
testcase_60 AC 330 ms
118,912 KB
testcase_61 AC 621 ms
143,680 KB
testcase_62 AC 701 ms
166,324 KB
testcase_63 AC 620 ms
142,296 KB
testcase_64 AC 407 ms
136,320 KB
testcase_65 AC 696 ms
160,976 KB
testcase_66 AC 743 ms
167,072 KB
testcase_67 AC 563 ms
137,088 KB
testcase_68 AC 467 ms
139,392 KB
testcase_69 AC 615 ms
141,244 KB
testcase_70 AC 576 ms
139,592 KB
testcase_71 AC 356 ms
124,160 KB
testcase_72 AC 789 ms
195,344 KB
testcase_73 AC 709 ms
170,516 KB
testcase_74 AC 451 ms
128,256 KB
testcase_75 AC 689 ms
186,936 KB
testcase_76 AC 522 ms
131,416 KB
testcase_77 AC 353 ms
124,288 KB
testcase_78 AC 421 ms
132,352 KB
testcase_79 AC 337 ms
119,552 KB
testcase_80 AC 742 ms
194,260 KB
testcase_81 AC 659 ms
169,968 KB
testcase_82 AC 522 ms
132,356 KB
testcase_83 AC 541 ms
134,332 KB
testcase_84 AC 501 ms
129,664 KB
testcase_85 AC 140 ms
81,704 KB
testcase_86 AC 479 ms
128,128 KB
testcase_87 AC 567 ms
139,732 KB
testcase_88 AC 303 ms
115,456 KB
testcase_89 AC 433 ms
133,004 KB
testcase_90 AC 273 ms
111,744 KB
testcase_91 AC 470 ms
137,988 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

class LiChaoTree:
    def __init__(self, xx, getmin=1):
        self._inf = (1 << 63)-1
        self._rev = getmin*2-1
        self._n = 1 << (len(xx)-1).bit_length()
        self._aa = [None]*(2*self._n)
        self._bb = [None]*(2*self._n)
        self._ll = [None]*(2*self._n)
        self._rr = [None]*(2*self._n)
        self._xtou = {}
        for u, x in enumerate(xx, self._n):
            self._ll[u] = self._rr[u] = x
            self._xtou[x] = u
        for u in range(1, self._n)[::-1]:
            self._ll[u], self._rr[u] = self._ll[u*2], self._rr[u*2+1]
            if self._rr[u] == None: self._rr[u] = self._rr[u*2]

    def add_line(self, a, b):
        u = 1
        while 1:
            if self._ll[u] == None: return
            if self._aa[u] == None:
                self._aa[u], self._bb[u] = a, b
                return
            c, d = self._aa[u], self._bb[u]
            l, r = self._ll[u], self._rr[u]
            yl, yr = a*l+b, a*r+b
            zl, zr = c*l+d, c*r+d
            if (yl-zl)*self._rev >= 0 and (yr-zr)*self._rev >= 0: return
            if (yl-zl)*self._rev <= 0 and (yr-zr)*self._rev <= 0:
                self._aa[u], self._bb[u] = a, b
                return
            if ((a-c)*self._rr[u*2]+b-d)*self._rev <= 0: a, b, self._aa[u], self._bb[u], yr, zr = c, d, a, b, zr, yr
            u = u*2+((yr-zr)*self._rev < 0)

    def __getitem__(self, x):
        if self._aa[1] == None: return self._rev*self._inf
        u = self._xtou[x]
        res = self._aa[1]*x+self._bb[1]
        while u > 1:
            if self._aa[u] != None:
                cur = self._aa[u]*x+self._bb[u]
                if (cur-res)*self._rev < 0: res = cur
            u >>= 1
        return res

n, a, b, w = LI()
dd = LI()

cht = LiChaoTree(list(range(n)))
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