結果
問題 | No.409 ダイエット |
ユーザー | mkawa2 |
提出日時 | 2023-02-06 23:49:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 226 ms / 2,000 ms |
コード長 | 1,792 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 82,320 KB |
実行使用メモリ | 116,224 KB |
最終ジャッジ日時 | 2024-07-05 01:08:10 |
合計ジャッジ時間 | 12,278 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
54,272 KB |
testcase_01 | AC | 42 ms
53,504 KB |
testcase_02 | AC | 45 ms
54,272 KB |
testcase_03 | AC | 41 ms
54,016 KB |
testcase_04 | AC | 40 ms
54,016 KB |
testcase_05 | AC | 42 ms
54,144 KB |
testcase_06 | AC | 41 ms
53,888 KB |
testcase_07 | AC | 41 ms
54,272 KB |
testcase_08 | AC | 40 ms
53,632 KB |
testcase_09 | AC | 41 ms
54,016 KB |
testcase_10 | AC | 41 ms
53,888 KB |
testcase_11 | AC | 40 ms
54,272 KB |
testcase_12 | AC | 41 ms
54,272 KB |
testcase_13 | AC | 40 ms
54,016 KB |
testcase_14 | AC | 40 ms
54,016 KB |
testcase_15 | AC | 41 ms
53,888 KB |
testcase_16 | AC | 42 ms
53,888 KB |
testcase_17 | AC | 41 ms
53,760 KB |
testcase_18 | AC | 41 ms
54,272 KB |
testcase_19 | AC | 40 ms
53,888 KB |
testcase_20 | AC | 41 ms
53,760 KB |
testcase_21 | AC | 41 ms
54,016 KB |
testcase_22 | AC | 42 ms
53,928 KB |
testcase_23 | AC | 40 ms
53,888 KB |
testcase_24 | AC | 41 ms
54,016 KB |
testcase_25 | AC | 40 ms
53,888 KB |
testcase_26 | AC | 40 ms
54,272 KB |
testcase_27 | AC | 41 ms
53,632 KB |
testcase_28 | AC | 42 ms
54,144 KB |
testcase_29 | AC | 42 ms
54,144 KB |
testcase_30 | AC | 41 ms
54,272 KB |
testcase_31 | AC | 41 ms
54,272 KB |
testcase_32 | AC | 40 ms
54,016 KB |
testcase_33 | AC | 41 ms
54,272 KB |
testcase_34 | AC | 40 ms
54,016 KB |
testcase_35 | AC | 75 ms
73,984 KB |
testcase_36 | AC | 72 ms
74,384 KB |
testcase_37 | AC | 67 ms
72,320 KB |
testcase_38 | AC | 69 ms
73,344 KB |
testcase_39 | AC | 75 ms
74,496 KB |
testcase_40 | AC | 81 ms
76,928 KB |
testcase_41 | AC | 64 ms
71,424 KB |
testcase_42 | AC | 79 ms
76,544 KB |
testcase_43 | AC | 67 ms
72,704 KB |
testcase_44 | AC | 67 ms
72,192 KB |
testcase_45 | AC | 70 ms
74,240 KB |
testcase_46 | AC | 79 ms
76,672 KB |
testcase_47 | AC | 77 ms
76,544 KB |
testcase_48 | AC | 79 ms
76,544 KB |
testcase_49 | AC | 66 ms
71,296 KB |
testcase_50 | AC | 72 ms
74,368 KB |
testcase_51 | AC | 68 ms
72,448 KB |
testcase_52 | AC | 67 ms
72,576 KB |
testcase_53 | AC | 71 ms
74,368 KB |
testcase_54 | AC | 70 ms
72,576 KB |
testcase_55 | AC | 161 ms
94,848 KB |
testcase_56 | AC | 116 ms
115,712 KB |
testcase_57 | AC | 211 ms
108,796 KB |
testcase_58 | AC | 145 ms
92,288 KB |
testcase_59 | AC | 180 ms
100,992 KB |
testcase_60 | AC | 144 ms
90,240 KB |
testcase_61 | AC | 211 ms
111,488 KB |
testcase_62 | AC | 197 ms
116,096 KB |
testcase_63 | AC | 203 ms
111,344 KB |
testcase_64 | AC | 146 ms
94,904 KB |
testcase_65 | AC | 209 ms
111,232 KB |
testcase_66 | AC | 221 ms
116,224 KB |
testcase_67 | AC | 192 ms
106,880 KB |
testcase_68 | AC | 175 ms
100,864 KB |
testcase_69 | AC | 220 ms
111,360 KB |
testcase_70 | AC | 207 ms
101,988 KB |
testcase_71 | AC | 154 ms
93,824 KB |
testcase_72 | AC | 226 ms
111,976 KB |
testcase_73 | AC | 221 ms
105,404 KB |
testcase_74 | AC | 159 ms
98,944 KB |
testcase_75 | AC | 223 ms
105,400 KB |
testcase_76 | AC | 172 ms
104,704 KB |
testcase_77 | AC | 157 ms
93,568 KB |
testcase_78 | AC | 148 ms
96,384 KB |
testcase_79 | AC | 149 ms
92,032 KB |
testcase_80 | AC | 213 ms
109,536 KB |
testcase_81 | AC | 226 ms
105,100 KB |
testcase_82 | AC | 184 ms
104,320 KB |
testcase_83 | AC | 190 ms
105,216 KB |
testcase_84 | AC | 178 ms
101,248 KB |
testcase_85 | AC | 96 ms
77,056 KB |
testcase_86 | AC | 176 ms
98,432 KB |
testcase_87 | AC | 207 ms
102,024 KB |
testcase_88 | AC | 145 ms
89,472 KB |
testcase_89 | AC | 182 ms
104,576 KB |
testcase_90 | AC | 139 ms
88,064 KB |
testcase_91 | AC | 183 ms
108,544 KB |
ソースコード
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[-1] e, f = self.ab[-2] if (b-d)*(e-c) > (d-f)*(c-a): break self.ab.pop() 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[0] c, d = self.ab[1] if a*x+b < c*x+d: break self.ab.popleft() 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)