結果

問題 No.409 ダイエット
ユーザー cielciel
提出日時 2016-04-25 21:12:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,682 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 69,432 KB
最終ジャッジ日時 2024-04-15 04:31:27
合計ジャッジ時間 53,575 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,008 KB
testcase_01 AC 30 ms
11,008 KB
testcase_02 AC 31 ms
11,008 KB
testcase_03 AC 32 ms
11,008 KB
testcase_04 AC 31 ms
11,008 KB
testcase_05 AC 31 ms
11,008 KB
testcase_06 AC 30 ms
11,136 KB
testcase_07 AC 30 ms
11,008 KB
testcase_08 AC 30 ms
11,008 KB
testcase_09 AC 31 ms
11,008 KB
testcase_10 AC 30 ms
11,136 KB
testcase_11 AC 31 ms
11,008 KB
testcase_12 AC 31 ms
11,008 KB
testcase_13 AC 30 ms
11,008 KB
testcase_14 AC 30 ms
11,008 KB
testcase_15 AC 30 ms
11,008 KB
testcase_16 AC 30 ms
11,008 KB
testcase_17 AC 31 ms
11,136 KB
testcase_18 AC 30 ms
11,008 KB
testcase_19 AC 31 ms
11,008 KB
testcase_20 AC 30 ms
11,008 KB
testcase_21 AC 31 ms
11,008 KB
testcase_22 AC 31 ms
11,136 KB
testcase_23 AC 31 ms
11,008 KB
testcase_24 AC 30 ms
11,136 KB
testcase_25 AC 30 ms
11,008 KB
testcase_26 AC 31 ms
11,008 KB
testcase_27 AC 31 ms
11,008 KB
testcase_28 AC 31 ms
11,008 KB
testcase_29 AC 30 ms
11,008 KB
testcase_30 AC 30 ms
11,008 KB
testcase_31 AC 31 ms
11,008 KB
testcase_32 AC 31 ms
11,008 KB
testcase_33 AC 31 ms
11,008 KB
testcase_34 AC 31 ms
11,136 KB
testcase_35 AC 47 ms
11,264 KB
testcase_36 AC 48 ms
11,264 KB
testcase_37 AC 48 ms
11,392 KB
testcase_38 AC 49 ms
11,392 KB
testcase_39 AC 48 ms
11,392 KB
testcase_40 AC 49 ms
11,264 KB
testcase_41 AC 50 ms
11,520 KB
testcase_42 AC 50 ms
11,648 KB
testcase_43 AC 48 ms
11,520 KB
testcase_44 AC 48 ms
11,392 KB
testcase_45 AC 49 ms
11,648 KB
testcase_46 AC 49 ms
11,392 KB
testcase_47 AC 50 ms
11,392 KB
testcase_48 AC 48 ms
11,520 KB
testcase_49 AC 49 ms
11,520 KB
testcase_50 AC 49 ms
11,392 KB
testcase_51 AC 50 ms
11,392 KB
testcase_52 AC 49 ms
11,520 KB
testcase_53 AC 50 ms
11,392 KB
testcase_54 AC 47 ms
11,264 KB
testcase_55 AC 906 ms
36,716 KB
testcase_56 AC 1,244 ms
26,680 KB
testcase_57 AC 1,890 ms
67,996 KB
testcase_58 AC 830 ms
35,292 KB
testcase_59 AC 1,123 ms
36,284 KB
testcase_60 AC 759 ms
31,972 KB
testcase_61 AC 1,613 ms
58,604 KB
testcase_62 AC 1,690 ms
67,304 KB
testcase_63 AC 1,682 ms
54,248 KB
testcase_64 AC 883 ms
32,624 KB
testcase_65 AC 1,763 ms
42,144 KB
testcase_66 AC 1,812 ms
59,636 KB
testcase_67 AC 1,469 ms
52,568 KB
testcase_68 AC 1,195 ms
36,056 KB
testcase_69 AC 1,647 ms
51,564 KB
testcase_70 AC 1,692 ms
55,308 KB
testcase_71 AC 917 ms
37,656 KB
testcase_72 TLE -
testcase_73 AC 1,925 ms
48,992 KB
testcase_74 AC 1,097 ms
44,816 KB
testcase_75 AC 1,812 ms
53,140 KB
testcase_76 AC 1,249 ms
49,936 KB
testcase_77 AC 922 ms
28,196 KB
testcase_78 AC 943 ms
42,240 KB
testcase_79 AC 822 ms
31,916 KB
testcase_80 AC 1,807 ms
66,240 KB
testcase_81 AC 1,858 ms
50,744 KB
testcase_82 AC 1,373 ms
47,840 KB
testcase_83 AC 1,461 ms
48,296 KB
testcase_84 AC 1,221 ms
32,984 KB
testcase_85 AC 159 ms
14,080 KB
testcase_86 AC 1,220 ms
34,648 KB
testcase_87 AC 1,724 ms
58,312 KB
testcase_88 AC 684 ms
26,148 KB
testcase_89 AC 1,356 ms
26,228 KB
testcase_90 AC 633 ms
19,296 KB
testcase_91 AC 1,450 ms
27,092 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