結果

問題 No.409 ダイエット
ユーザー cielciel
提出日時 2016-04-25 21:12:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 1,682 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 127,840 KB
最終ジャッジ日時 2023-09-08 16:43:07
合計ジャッジ時間 19,674 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,220 KB
testcase_01 AC 73 ms
71,272 KB
testcase_02 AC 73 ms
71,052 KB
testcase_03 AC 75 ms
71,264 KB
testcase_04 AC 74 ms
71,148 KB
testcase_05 AC 75 ms
71,328 KB
testcase_06 AC 74 ms
71,212 KB
testcase_07 AC 73 ms
71,260 KB
testcase_08 AC 74 ms
71,048 KB
testcase_09 AC 73 ms
71,048 KB
testcase_10 AC 75 ms
71,144 KB
testcase_11 AC 75 ms
71,000 KB
testcase_12 AC 74 ms
71,232 KB
testcase_13 AC 73 ms
71,224 KB
testcase_14 AC 75 ms
71,044 KB
testcase_15 AC 75 ms
71,228 KB
testcase_16 AC 76 ms
71,124 KB
testcase_17 AC 76 ms
71,120 KB
testcase_18 AC 74 ms
71,324 KB
testcase_19 AC 75 ms
71,412 KB
testcase_20 AC 75 ms
71,276 KB
testcase_21 AC 75 ms
71,228 KB
testcase_22 AC 74 ms
71,120 KB
testcase_23 AC 75 ms
71,228 KB
testcase_24 AC 75 ms
70,916 KB
testcase_25 AC 74 ms
71,028 KB
testcase_26 AC 74 ms
71,308 KB
testcase_27 AC 75 ms
71,316 KB
testcase_28 AC 75 ms
71,220 KB
testcase_29 AC 76 ms
71,404 KB
testcase_30 AC 74 ms
71,428 KB
testcase_31 AC 74 ms
70,900 KB
testcase_32 AC 75 ms
71,144 KB
testcase_33 AC 75 ms
71,128 KB
testcase_34 AC 76 ms
71,304 KB
testcase_35 AC 129 ms
78,344 KB
testcase_36 AC 137 ms
79,020 KB
testcase_37 AC 145 ms
78,468 KB
testcase_38 AC 136 ms
78,844 KB
testcase_39 AC 129 ms
78,592 KB
testcase_40 AC 139 ms
78,972 KB
testcase_41 AC 119 ms
77,712 KB
testcase_42 AC 131 ms
78,968 KB
testcase_43 AC 115 ms
77,696 KB
testcase_44 AC 131 ms
78,320 KB
testcase_45 AC 139 ms
79,244 KB
testcase_46 AC 137 ms
78,504 KB
testcase_47 AC 134 ms
79,012 KB
testcase_48 AC 130 ms
78,568 KB
testcase_49 AC 126 ms
78,348 KB
testcase_50 AC 130 ms
78,392 KB
testcase_51 AC 143 ms
78,456 KB
testcase_52 AC 129 ms
78,024 KB
testcase_53 AC 131 ms
78,636 KB
testcase_54 AC 128 ms
78,356 KB
testcase_55 AC 232 ms
97,128 KB
testcase_56 AC 172 ms
106,464 KB
testcase_57 AC 331 ms
124,276 KB
testcase_58 AC 225 ms
96,052 KB
testcase_59 AC 281 ms
97,388 KB
testcase_60 AC 222 ms
93,488 KB
testcase_61 AC 301 ms
115,568 KB
testcase_62 AC 323 ms
123,592 KB
testcase_63 AC 314 ms
112,640 KB
testcase_64 AC 249 ms
94,520 KB
testcase_65 AC 308 ms
104,440 KB
testcase_66 AC 347 ms
118,280 KB
testcase_67 AC 290 ms
111,264 KB
testcase_68 AC 273 ms
97,724 KB
testcase_69 AC 315 ms
109,616 KB
testcase_70 AC 315 ms
114,052 KB
testcase_71 AC 229 ms
97,576 KB
testcase_72 AC 329 ms
127,840 KB
testcase_73 AC 354 ms
108,700 KB
testcase_74 AC 250 ms
103,900 KB
testcase_75 AC 324 ms
110,144 KB
testcase_76 AC 276 ms
108,664 KB
testcase_77 AC 253 ms
91,812 KB
testcase_78 AC 233 ms
101,308 KB
testcase_79 AC 228 ms
92,232 KB
testcase_80 AC 343 ms
120,452 KB
testcase_81 AC 328 ms
108,968 KB
testcase_82 AC 282 ms
105,616 KB
testcase_83 AC 297 ms
107,092 KB
testcase_84 AC 275 ms
96,232 KB
testcase_85 AC 170 ms
80,336 KB
testcase_86 AC 290 ms
96,180 KB
testcase_87 AC 302 ms
113,704 KB
testcase_88 AC 234 ms
88,944 KB
testcase_89 AC 232 ms
99,084 KB
testcase_90 AC 207 ms
85,208 KB
testcase_91 AC 241 ms
101,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
#This code does not check the correctness of the algorithm.

import sys
if sys.version_info[0]>=3: raw_input=input

#http://stackoverflow.com/questions/4544630/automatically-growing-lists-in-python
class GrowingList(list):
	def __init__(self,val=None):
		self.val=val
	def __getitem__(self, index):
		if index >= len(self):
			return self.val
		return list.__getitem__(self, index)
	def __setitem__(self, index, value):
		if index >= len(self):
			self.extend([self.val for _ in range(index + 1 - len(self))])
		list.__setitem__(self, index, value)

def is_minimam(a1,b1,a2,b2,a3,b3):
	return (a2-a1)*(b3-b2)>=(b2-b1)*(a3-a2)

def is_maximam(a1,b1,a2,b2,a3,b3):
	return is_minimam(-a1,-b1,-a2,-b2,-a3,-b3)

def check(l1,l2,l3):
	return is_minimam(l1[0],l1[1],l2[0],l2[1],l3[0],l3[1])

def calc(l,now):
	return l[0]*now+l[1]

class ConvexHullTrick:
	def __init__(self):
		self.deque=GrowingList([0,0])
		self.s=0
		self.t=0
	def add(self,a,b):
		l=[a,b]
		while self.s+1<self.t and check(self.deque[self.t-2],self.deque[self.t-1],l):
			self.t-=1
		self.deque[self.t]=l
		self.t+=1
	def get(self,now):
		while self.s+1<self.t and calc(self.deque[self.s],now)>=calc(self.deque[self.s+1],now):
			self.s+=1
		return calc(self.deque[self.s],now)

n,a,b,w=map(int,raw_input().split())
deq=ConvexHullTrick()
z = w + 0 * a + b * 0 * (0 - 1) // 2
deq.add( - 0 * b, z)
r = z - a * (n - 0) + b * (n - 0) * (n - 0 + 1) // 2
for i,e in enumerate(raw_input().split()):
	z = int(e) - i * a + ( b * i * (i + 1)) // 2 + deq.get(i)
	deq.add( - (i + 1) * b , z + (i + 1) * a + ( b * (i + 1) * i) // 2)
	r = min(r,z - a * (n -(i+1)) + b * (n - (i+1)) * (n - (i+1) + 1) // 2)
print(r)
0