結果

問題 No.409 ダイエット
ユーザー cielciel
提出日時 2016-04-25 21:11:05
言語 Python2
(2.7.18)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,682 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 64,460 KB
最終ジャッジ日時 2024-04-15 04:30:01
合計ジャッジ時間 55,427 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,812 KB
testcase_01 AC 10 ms
6,940 KB
testcase_02 AC 9 ms
6,940 KB
testcase_03 AC 10 ms
6,940 KB
testcase_04 AC 10 ms
6,940 KB
testcase_05 AC 9 ms
6,944 KB
testcase_06 AC 10 ms
6,944 KB
testcase_07 AC 10 ms
6,940 KB
testcase_08 AC 10 ms
6,940 KB
testcase_09 AC 10 ms
6,940 KB
testcase_10 AC 10 ms
6,940 KB
testcase_11 AC 12 ms
6,944 KB
testcase_12 AC 11 ms
6,944 KB
testcase_13 AC 9 ms
6,940 KB
testcase_14 AC 10 ms
6,940 KB
testcase_15 AC 9 ms
6,940 KB
testcase_16 AC 10 ms
6,940 KB
testcase_17 AC 10 ms
6,944 KB
testcase_18 AC 10 ms
6,940 KB
testcase_19 AC 9 ms
6,940 KB
testcase_20 AC 10 ms
6,944 KB
testcase_21 AC 9 ms
6,940 KB
testcase_22 AC 10 ms
6,944 KB
testcase_23 AC 10 ms
6,940 KB
testcase_24 AC 11 ms
6,944 KB
testcase_25 AC 10 ms
6,944 KB
testcase_26 AC 9 ms
6,940 KB
testcase_27 AC 9 ms
6,944 KB
testcase_28 AC 10 ms
6,940 KB
testcase_29 AC 10 ms
6,940 KB
testcase_30 AC 9 ms
6,940 KB
testcase_31 AC 10 ms
6,944 KB
testcase_32 AC 9 ms
6,940 KB
testcase_33 AC 10 ms
6,940 KB
testcase_34 AC 9 ms
6,940 KB
testcase_35 AC 28 ms
6,940 KB
testcase_36 AC 29 ms
6,940 KB
testcase_37 AC 27 ms
6,940 KB
testcase_38 AC 28 ms
6,944 KB
testcase_39 AC 28 ms
6,940 KB
testcase_40 AC 31 ms
6,940 KB
testcase_41 AC 30 ms
6,940 KB
testcase_42 AC 32 ms
6,944 KB
testcase_43 AC 26 ms
6,940 KB
testcase_44 AC 27 ms
6,944 KB
testcase_45 AC 30 ms
6,944 KB
testcase_46 AC 30 ms
6,944 KB
testcase_47 AC 29 ms
6,940 KB
testcase_48 AC 28 ms
6,940 KB
testcase_49 AC 28 ms
6,940 KB
testcase_50 AC 28 ms
6,944 KB
testcase_51 AC 32 ms
6,944 KB
testcase_52 AC 28 ms
6,940 KB
testcase_53 AC 31 ms
6,940 KB
testcase_54 AC 28 ms
6,944 KB
testcase_55 AC 947 ms
31,696 KB
testcase_56 AC 1,679 ms
21,504 KB
testcase_57 AC 1,981 ms
63,632 KB
testcase_58 AC 869 ms
30,512 KB
testcase_59 AC 1,206 ms
30,980 KB
testcase_60 AC 800 ms
27,320 KB
testcase_61 AC 1,657 ms
53,140 KB
testcase_62 AC 1,740 ms
62,812 KB
testcase_63 AC 1,803 ms
49,612 KB
testcase_64 AC 947 ms
27,848 KB
testcase_65 TLE -
testcase_66 AC 1,908 ms
54,884 KB
testcase_67 AC 1,564 ms
47,784 KB
testcase_68 AC 1,287 ms
30,824 KB
testcase_69 AC 1,879 ms
46,668 KB
testcase_70 AC 1,709 ms
51,976 KB
testcase_71 AC 945 ms
32,392 KB
testcase_72 TLE -
testcase_73 TLE -
testcase_74 AC 1,088 ms
40,800 KB
testcase_75 AC 1,813 ms
49,872 KB
testcase_76 AC 1,225 ms
45,796 KB
testcase_77 AC 943 ms
23,344 KB
testcase_78 AC 891 ms
38,084 KB
testcase_79 AC 826 ms
27,468 KB
testcase_80 AC 1,792 ms
60,484 KB
testcase_81 AC 1,903 ms
46,788 KB
testcase_82 AC 1,409 ms
43,700 KB
testcase_83 AC 1,477 ms
44,556 KB
testcase_84 AC 1,342 ms
28,700 KB
testcase_85 AC 144 ms
9,344 KB
testcase_86 AC 1,247 ms
30,368 KB
testcase_87 AC 1,717 ms
53,036 KB
testcase_88 AC 690 ms
20,792 KB
testcase_89 AC 1,451 ms
21,844 KB
testcase_90 AC 651 ms
14,856 KB
testcase_91 AC 1,531 ms
22,840 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