結果

問題 No.409 ダイエット
ユーザー cielciel
提出日時 2016-04-25 21:11:36
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 352 ms / 2,000 ms
コード長 1,682 bytes
コンパイル時間 1,482 ms
コンパイル使用メモリ 77,360 KB
実行使用メモリ 130,972 KB
最終ジャッジ日時 2023-09-08 16:42:15
合計ジャッジ時間 22,175 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
76,332 KB
testcase_01 AC 75 ms
76,356 KB
testcase_02 AC 74 ms
76,264 KB
testcase_03 AC 73 ms
76,340 KB
testcase_04 AC 74 ms
76,356 KB
testcase_05 AC 76 ms
76,284 KB
testcase_06 AC 75 ms
76,312 KB
testcase_07 AC 75 ms
76,080 KB
testcase_08 AC 75 ms
76,084 KB
testcase_09 AC 73 ms
76,380 KB
testcase_10 AC 73 ms
76,500 KB
testcase_11 AC 73 ms
76,144 KB
testcase_12 AC 73 ms
76,344 KB
testcase_13 AC 74 ms
76,108 KB
testcase_14 AC 75 ms
76,352 KB
testcase_15 AC 75 ms
76,380 KB
testcase_16 AC 72 ms
76,356 KB
testcase_17 AC 72 ms
76,288 KB
testcase_18 AC 74 ms
76,180 KB
testcase_19 AC 75 ms
76,352 KB
testcase_20 AC 75 ms
76,260 KB
testcase_21 AC 74 ms
76,196 KB
testcase_22 AC 74 ms
76,088 KB
testcase_23 AC 75 ms
76,308 KB
testcase_24 AC 75 ms
76,180 KB
testcase_25 AC 74 ms
76,264 KB
testcase_26 AC 77 ms
76,432 KB
testcase_27 AC 75 ms
76,308 KB
testcase_28 AC 75 ms
76,132 KB
testcase_29 AC 75 ms
76,380 KB
testcase_30 AC 74 ms
76,508 KB
testcase_31 AC 74 ms
76,388 KB
testcase_32 AC 74 ms
76,140 KB
testcase_33 AC 77 ms
76,144 KB
testcase_34 AC 75 ms
76,148 KB
testcase_35 AC 139 ms
79,932 KB
testcase_36 AC 135 ms
80,504 KB
testcase_37 AC 122 ms
80,224 KB
testcase_38 AC 133 ms
80,196 KB
testcase_39 AC 127 ms
80,012 KB
testcase_40 AC 132 ms
80,516 KB
testcase_41 AC 122 ms
80,164 KB
testcase_42 AC 133 ms
80,220 KB
testcase_43 AC 112 ms
80,368 KB
testcase_44 AC 127 ms
80,432 KB
testcase_45 AC 134 ms
80,548 KB
testcase_46 AC 136 ms
80,216 KB
testcase_47 AC 139 ms
80,496 KB
testcase_48 AC 126 ms
80,728 KB
testcase_49 AC 114 ms
80,388 KB
testcase_50 AC 133 ms
80,760 KB
testcase_51 AC 126 ms
80,280 KB
testcase_52 AC 129 ms
80,448 KB
testcase_53 AC 135 ms
80,504 KB
testcase_54 AC 131 ms
80,284 KB
testcase_55 AC 240 ms
100,688 KB
testcase_56 AC 168 ms
108,904 KB
testcase_57 AC 333 ms
126,792 KB
testcase_58 AC 232 ms
98,244 KB
testcase_59 AC 285 ms
100,156 KB
testcase_60 AC 224 ms
95,632 KB
testcase_61 AC 301 ms
118,124 KB
testcase_62 AC 316 ms
126,488 KB
testcase_63 AC 322 ms
115,820 KB
testcase_64 AC 262 ms
98,304 KB
testcase_65 AC 327 ms
106,996 KB
testcase_66 AC 342 ms
119,428 KB
testcase_67 AC 292 ms
113,664 KB
testcase_68 AC 285 ms
99,640 KB
testcase_69 AC 332 ms
113,452 KB
testcase_70 AC 318 ms
118,756 KB
testcase_71 AC 231 ms
99,600 KB
testcase_72 AC 342 ms
130,972 KB
testcase_73 AC 352 ms
114,316 KB
testcase_74 AC 242 ms
108,676 KB
testcase_75 AC 333 ms
116,180 KB
testcase_76 AC 275 ms
113,988 KB
testcase_77 AC 248 ms
94,060 KB
testcase_78 AC 227 ms
104,664 KB
testcase_79 AC 216 ms
95,816 KB
testcase_80 AC 329 ms
125,732 KB
testcase_81 AC 346 ms
115,580 KB
testcase_82 AC 277 ms
111,608 KB
testcase_83 AC 298 ms
111,988 KB
testcase_84 AC 280 ms
100,356 KB
testcase_85 AC 174 ms
82,328 KB
testcase_86 AC 286 ms
101,232 KB
testcase_87 AC 307 ms
119,036 KB
testcase_88 AC 235 ms
92,132 KB
testcase_89 AC 242 ms
102,464 KB
testcase_90 AC 222 ms
88,992 KB
testcase_91 AC 246 ms
105,740 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