結果
問題 | No.409 ダイエット |
ユーザー | mkawa2 |
提出日時 | 2023-02-07 11:17:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 293 ms / 2,000 ms |
コード長 | 3,411 bytes |
コンパイル時間 | 244 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 115,712 KB |
最終ジャッジ日時 | 2024-07-05 08:56:07 |
合計ジャッジ時間 | 15,731 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
54,144 KB |
testcase_01 | AC | 46 ms
54,528 KB |
testcase_02 | AC | 50 ms
54,144 KB |
testcase_03 | AC | 47 ms
54,400 KB |
testcase_04 | AC | 47 ms
53,888 KB |
testcase_05 | AC | 47 ms
54,144 KB |
testcase_06 | AC | 49 ms
54,272 KB |
testcase_07 | AC | 46 ms
54,656 KB |
testcase_08 | AC | 49 ms
54,400 KB |
testcase_09 | AC | 48 ms
54,400 KB |
testcase_10 | AC | 47 ms
54,400 KB |
testcase_11 | AC | 46 ms
54,144 KB |
testcase_12 | AC | 47 ms
54,272 KB |
testcase_13 | AC | 47 ms
54,016 KB |
testcase_14 | AC | 48 ms
54,272 KB |
testcase_15 | AC | 47 ms
54,272 KB |
testcase_16 | AC | 46 ms
54,656 KB |
testcase_17 | AC | 50 ms
54,400 KB |
testcase_18 | AC | 47 ms
54,400 KB |
testcase_19 | AC | 47 ms
54,784 KB |
testcase_20 | AC | 46 ms
54,272 KB |
testcase_21 | AC | 49 ms
54,400 KB |
testcase_22 | AC | 47 ms
54,016 KB |
testcase_23 | AC | 47 ms
54,144 KB |
testcase_24 | AC | 49 ms
54,272 KB |
testcase_25 | AC | 46 ms
54,656 KB |
testcase_26 | AC | 47 ms
54,400 KB |
testcase_27 | AC | 47 ms
54,016 KB |
testcase_28 | AC | 46 ms
54,400 KB |
testcase_29 | AC | 46 ms
54,016 KB |
testcase_30 | AC | 48 ms
54,272 KB |
testcase_31 | AC | 46 ms
54,400 KB |
testcase_32 | AC | 47 ms
54,528 KB |
testcase_33 | AC | 46 ms
54,400 KB |
testcase_34 | AC | 48 ms
54,016 KB |
testcase_35 | AC | 94 ms
76,544 KB |
testcase_36 | AC | 93 ms
76,288 KB |
testcase_37 | AC | 85 ms
73,344 KB |
testcase_38 | AC | 85 ms
73,600 KB |
testcase_39 | AC | 88 ms
74,880 KB |
testcase_40 | AC | 99 ms
76,800 KB |
testcase_41 | AC | 84 ms
72,576 KB |
testcase_42 | AC | 99 ms
76,800 KB |
testcase_43 | AC | 85 ms
73,600 KB |
testcase_44 | AC | 90 ms
73,728 KB |
testcase_45 | AC | 96 ms
76,416 KB |
testcase_46 | AC | 96 ms
77,056 KB |
testcase_47 | AC | 100 ms
76,928 KB |
testcase_48 | AC | 102 ms
76,800 KB |
testcase_49 | AC | 80 ms
72,192 KB |
testcase_50 | AC | 97 ms
77,056 KB |
testcase_51 | AC | 87 ms
74,368 KB |
testcase_52 | AC | 86 ms
73,984 KB |
testcase_53 | AC | 96 ms
76,672 KB |
testcase_54 | AC | 95 ms
76,672 KB |
testcase_55 | AC | 197 ms
95,488 KB |
testcase_56 | AC | 140 ms
107,448 KB |
testcase_57 | AC | 248 ms
109,040 KB |
testcase_58 | AC | 179 ms
93,056 KB |
testcase_59 | AC | 228 ms
101,120 KB |
testcase_60 | AC | 173 ms
90,624 KB |
testcase_61 | AC | 229 ms
111,488 KB |
testcase_62 | AC | 235 ms
115,712 KB |
testcase_63 | AC | 259 ms
110,976 KB |
testcase_64 | AC | 206 ms
95,360 KB |
testcase_65 | AC | 281 ms
111,488 KB |
testcase_66 | AC | 268 ms
109,496 KB |
testcase_67 | AC | 236 ms
107,008 KB |
testcase_68 | AC | 239 ms
100,608 KB |
testcase_69 | AC | 265 ms
111,232 KB |
testcase_70 | AC | 253 ms
101,880 KB |
testcase_71 | AC | 187 ms
94,208 KB |
testcase_72 | AC | 268 ms
112,264 KB |
testcase_73 | AC | 293 ms
105,220 KB |
testcase_74 | AC | 190 ms
98,176 KB |
testcase_75 | AC | 273 ms
107,584 KB |
testcase_76 | AC | 210 ms
104,832 KB |
testcase_77 | AC | 211 ms
93,568 KB |
testcase_78 | AC | 176 ms
96,000 KB |
testcase_79 | AC | 193 ms
91,904 KB |
testcase_80 | AC | 252 ms
111,364 KB |
testcase_81 | AC | 289 ms
105,392 KB |
testcase_82 | AC | 226 ms
104,704 KB |
testcase_83 | AC | 234 ms
104,832 KB |
testcase_84 | AC | 241 ms
101,096 KB |
testcase_85 | AC | 121 ms
77,440 KB |
testcase_86 | AC | 242 ms
98,048 KB |
testcase_87 | AC | 239 ms
102,188 KB |
testcase_88 | AC | 185 ms
89,216 KB |
testcase_89 | AC | 229 ms
104,704 KB |
testcase_90 | AC | 189 ms
87,976 KB |
testcase_91 | AC | 235 ms
108,288 KB |
ソースコード
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)