結果

問題 No.409 ダイエット
ユーザー cielciel
提出日時 2016-04-19 00:23:42
言語 Ruby
(3.3.0)
結果
AC  
実行時間 515 ms / 2,000 ms
コード長 1,156 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 11,320 KB
実行使用メモリ 44,984 KB
最終ジャッジ日時 2023-09-08 16:40:51
合計ジャッジ時間 21,275 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,168 KB
testcase_01 AC 78 ms
15,236 KB
testcase_02 AC 79 ms
15,120 KB
testcase_03 AC 77 ms
15,344 KB
testcase_04 AC 78 ms
15,132 KB
testcase_05 AC 77 ms
15,148 KB
testcase_06 AC 79 ms
15,264 KB
testcase_07 AC 78 ms
15,360 KB
testcase_08 AC 77 ms
15,272 KB
testcase_09 AC 78 ms
15,060 KB
testcase_10 AC 78 ms
15,240 KB
testcase_11 AC 77 ms
15,308 KB
testcase_12 AC 79 ms
15,300 KB
testcase_13 AC 80 ms
15,068 KB
testcase_14 AC 78 ms
15,140 KB
testcase_15 AC 77 ms
15,148 KB
testcase_16 AC 77 ms
15,132 KB
testcase_17 AC 77 ms
15,216 KB
testcase_18 AC 78 ms
15,252 KB
testcase_19 AC 77 ms
15,176 KB
testcase_20 AC 77 ms
15,148 KB
testcase_21 AC 78 ms
15,328 KB
testcase_22 AC 78 ms
15,368 KB
testcase_23 AC 79 ms
15,148 KB
testcase_24 AC 78 ms
15,152 KB
testcase_25 AC 79 ms
15,308 KB
testcase_26 AC 79 ms
15,136 KB
testcase_27 AC 80 ms
15,144 KB
testcase_28 AC 79 ms
15,232 KB
testcase_29 AC 78 ms
15,320 KB
testcase_30 AC 78 ms
15,252 KB
testcase_31 AC 79 ms
15,224 KB
testcase_32 AC 79 ms
15,148 KB
testcase_33 AC 79 ms
15,304 KB
testcase_34 AC 80 ms
15,248 KB
testcase_35 AC 83 ms
15,148 KB
testcase_36 AC 83 ms
15,180 KB
testcase_37 AC 82 ms
15,296 KB
testcase_38 AC 84 ms
15,368 KB
testcase_39 AC 83 ms
15,232 KB
testcase_40 AC 83 ms
15,268 KB
testcase_41 AC 83 ms
15,160 KB
testcase_42 AC 82 ms
15,180 KB
testcase_43 AC 82 ms
15,076 KB
testcase_44 AC 82 ms
15,176 KB
testcase_45 AC 83 ms
15,192 KB
testcase_46 AC 83 ms
15,180 KB
testcase_47 AC 83 ms
15,164 KB
testcase_48 AC 82 ms
15,032 KB
testcase_49 AC 82 ms
15,212 KB
testcase_50 AC 82 ms
15,164 KB
testcase_51 AC 83 ms
15,060 KB
testcase_52 AC 83 ms
15,132 KB
testcase_53 AC 85 ms
15,264 KB
testcase_54 AC 82 ms
15,128 KB
testcase_55 AC 272 ms
28,708 KB
testcase_56 AC 447 ms
37,240 KB
testcase_57 AC 489 ms
44,356 KB
testcase_58 AC 247 ms
27,532 KB
testcase_59 AC 324 ms
30,700 KB
testcase_60 AC 236 ms
26,144 KB
testcase_61 AC 433 ms
39,420 KB
testcase_62 AC 447 ms
42,776 KB
testcase_63 AC 430 ms
37,984 KB
testcase_64 AC 268 ms
28,144 KB
testcase_65 AC 471 ms
37,848 KB
testcase_66 AC 480 ms
41,880 KB
testcase_67 AC 379 ms
36,200 KB
testcase_68 AC 337 ms
30,316 KB
testcase_69 AC 436 ms
37,500 KB
testcase_70 AC 418 ms
38,852 KB
testcase_71 AC 261 ms
28,772 KB
testcase_72 AC 515 ms
44,984 KB
testcase_73 AC 472 ms
38,596 KB
testcase_74 AC 297 ms
31,892 KB
testcase_75 AC 471 ms
40,212 KB
testcase_76 AC 327 ms
34,596 KB
testcase_77 AC 270 ms
27,288 KB
testcase_78 AC 265 ms
30,304 KB
testcase_79 AC 245 ms
26,796 KB
testcase_80 AC 462 ms
42,956 KB
testcase_81 AC 458 ms
38,852 KB
testcase_82 AC 349 ms
34,664 KB
testcase_83 AC 368 ms
35,652 KB
testcase_84 AC 330 ms
29,892 KB
testcase_85 AC 109 ms
16,904 KB
testcase_86 AC 328 ms
29,804 KB
testcase_87 AC 415 ms
39,296 KB
testcase_88 AC 224 ms
24,224 KB
testcase_89 AC 377 ms
29,592 KB
testcase_90 AC 220 ms
23,064 KB
testcase_91 AC 397 ms
33,012 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:28: warning: mismatched indentations at 'end' with 'while' at 26
Main.rb:31: warning: mismatched indentations at 'end' with 'def' at 24
Main.rb:35: warning: mismatched indentations at 'end' with 'while' at 33
Main.rb:48: warning: `-' after local variable or literal is interpreted as binary operator
Main.rb:48: warning: even though it seems like unary operator
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
#Rubyが制限時間内に終了するかのテストです
#解法の検証ができているわけではありません

def is_minimam(a1,b1,a2,b2,a3,b3)
	(a2-a1)*(b3-b2)>=(b2-b1)*(a3-a2)
end
def is_maximam(a1,b1,a2,b2,a3,b3)
	is_minimam(-a1,-b1,-a2,-b2,-a3,-b3)
end
def check(l1,l2,l3)
	is_minimam(l1[0],l1[1],l2[0],l2[1],l3[0],l3[1])
end
def calc(l,now)
	l[0]*now+l[1]
end

class ConvexHullTrick
	def initialize
		@deque=[]
		@s=0
		@t=0
	end
	def add(a,b)
		l=[a,b]
        while @s+1<@t&&check(@deque[@t-2]||[0,0],@deque[@t-1]||[0,0],l)
			@t-=1
		end
		@deque[@t]=l
		@t+=1
    end
	def get(now)
        while @s+1<@t&&calc(@deque[@s]||[0,0],now)>=calc(@deque[@s+1]||[0,0],now)
			@s+=1
		end
        calc(@deque[@s],now)
	end
end

n,a,b,w=gets.split.map(&:to_i)
deq=ConvexHullTrick.new
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
gets.split.each_with_index{|e,i|
	z = e.to_i - 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 = [r,z - a * (n -(i+1)) + b * (n - (i+1)) * (n - (i+1) + 1) / 2].min
}
p r
0