結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
20,276 KB
testcase_01 AC 111 ms
20,432 KB
testcase_02 AC 113 ms
20,332 KB
testcase_03 AC 111 ms
20,340 KB
testcase_04 AC 112 ms
20,296 KB
testcase_05 AC 111 ms
20,424 KB
testcase_06 AC 109 ms
20,476 KB
testcase_07 AC 112 ms
20,340 KB
testcase_08 AC 112 ms
20,456 KB
testcase_09 AC 113 ms
20,276 KB
testcase_10 AC 113 ms
20,152 KB
testcase_11 AC 113 ms
20,264 KB
testcase_12 AC 112 ms
20,380 KB
testcase_13 AC 111 ms
20,148 KB
testcase_14 AC 111 ms
20,340 KB
testcase_15 AC 110 ms
20,144 KB
testcase_16 AC 111 ms
20,396 KB
testcase_17 AC 112 ms
20,256 KB
testcase_18 AC 117 ms
20,332 KB
testcase_19 AC 113 ms
20,144 KB
testcase_20 AC 112 ms
20,240 KB
testcase_21 AC 112 ms
20,376 KB
testcase_22 AC 110 ms
20,348 KB
testcase_23 AC 111 ms
20,284 KB
testcase_24 AC 110 ms
20,432 KB
testcase_25 AC 112 ms
20,392 KB
testcase_26 AC 112 ms
20,296 KB
testcase_27 AC 113 ms
20,304 KB
testcase_28 AC 113 ms
20,340 KB
testcase_29 AC 111 ms
20,260 KB
testcase_30 AC 111 ms
20,272 KB
testcase_31 AC 111 ms
20,256 KB
testcase_32 AC 111 ms
20,420 KB
testcase_33 AC 110 ms
20,296 KB
testcase_34 AC 112 ms
20,260 KB
testcase_35 AC 108 ms
20,148 KB
testcase_36 AC 108 ms
20,224 KB
testcase_37 AC 111 ms
20,336 KB
testcase_38 AC 109 ms
19,896 KB
testcase_39 AC 108 ms
20,048 KB
testcase_40 AC 108 ms
20,424 KB
testcase_41 AC 111 ms
20,236 KB
testcase_42 AC 112 ms
20,100 KB
testcase_43 AC 109 ms
20,364 KB
testcase_44 AC 108 ms
20,328 KB
testcase_45 AC 109 ms
20,244 KB
testcase_46 AC 108 ms
20,236 KB
testcase_47 AC 108 ms
20,116 KB
testcase_48 AC 108 ms
20,152 KB
testcase_49 AC 109 ms
20,248 KB
testcase_50 AC 111 ms
20,152 KB
testcase_51 AC 111 ms
20,152 KB
testcase_52 AC 110 ms
20,336 KB
testcase_53 AC 109 ms
20,244 KB
testcase_54 AC 108 ms
20,004 KB
testcase_55 AC 305 ms
34,060 KB
testcase_56 AC 512 ms
42,428 KB
testcase_57 AC 518 ms
42,936 KB
testcase_58 AC 282 ms
31,312 KB
testcase_59 AC 352 ms
39,116 KB
testcase_60 AC 266 ms
30,280 KB
testcase_61 AC 475 ms
43,056 KB
testcase_62 AC 472 ms
42,724 KB
testcase_63 AC 465 ms
42,324 KB
testcase_64 AC 292 ms
32,968 KB
testcase_65 AC 527 ms
42,148 KB
testcase_66 AC 500 ms
42,776 KB
testcase_67 AC 410 ms
41,564 KB
testcase_68 AC 364 ms
38,936 KB
testcase_69 AC 469 ms
42,128 KB
testcase_70 AC 439 ms
42,540 KB
testcase_71 AC 288 ms
32,936 KB
testcase_72 AC 538 ms
43,944 KB
testcase_73 AC 520 ms
43,572 KB
testcase_74 AC 325 ms
38,340 KB
testcase_75 AC 505 ms
43,612 KB
testcase_76 AC 362 ms
41,516 KB
testcase_77 AC 300 ms
32,384 KB
testcase_78 AC 295 ms
35,576 KB
testcase_79 AC 274 ms
30,816 KB
testcase_80 AC 490 ms
44,308 KB
testcase_81 AC 507 ms
43,372 KB
testcase_82 AC 393 ms
41,472 KB
testcase_83 AC 412 ms
41,640 KB
testcase_84 AC 356 ms
38,712 KB
testcase_85 AC 140 ms
21,256 KB
testcase_86 AC 361 ms
38,200 KB
testcase_87 AC 444 ms
42,764 KB
testcase_88 AC 249 ms
29,908 KB
testcase_89 AC 424 ms
40,980 KB
testcase_90 AC 253 ms
24,760 KB
testcase_91 AC 429 ms
41,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:26: warning: mismatched indentations at 'end' with 'while' at 24
Main.rb:29: warning: mismatched indentations at 'end' with 'def' at 22
Main.rb:33: warning: mismatched indentations at 'end' with 'while' at 31
Main.rb:52: warning: `-' after local variable or literal is interpreted as binary operator
Main.rb:52: warning: even though it seems like unary operator
Syntax OK

ソースコード

diff #

#!/usr/bin/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=100000.times.map{[0,0]}
		@s=0
		@t=0
	end
	def add(a,b)
		l=[a,b]
        while @s+1<@t&&check(@deque[@t-2],@deque[@t-1],l)
			@t-=1
		end
		@deque[@t]=l
		@t+=1
    end
	def get(now)
        while @s+1<@t&&calc(@deque[@s],now)>=calc(@deque[@s+1],now)
			@s+=1
		end
        calc(@deque[@s],now)
	end
end

n,a,b,w=gets.split.map(&:to_i)
d=gets.split.map(&:to_i)
deq=ConvexHullTrick.new
dp=[Float::INFINITY]*(n+1)
dp[0]=w

deq.add( - 0 * b,dp[0] + 0 * a + b * 0 * (0 - 1) / 2)
n.times{|i|
	dp[i + 1] = d[i] - i * a + ( b * i * (i + 1)) / 2 + deq.get(i)
	deq.add( - (i + 1) * b , dp[i + 1] + (i + 1) * a + ( b * (i + 1) * i) / 2)
}

res=Float::INFINITY
(n+1).times{|i|
	res=[res,dp[i] - a * (n -i) + b * (n - i) * (n - i + 1) / 2].min
}
p res
0