結果

問題 No.545 ママの大事な二人の子供
ユーザー cielciel
提出日時 2017-07-15 01:05:45
言語 Ruby
(3.3.0)
結果
AC  
実行時間 510 ms / 2,000 ms
コード長 428 bytes
コンパイル時間 41 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 20,608 KB
最終ジャッジ日時 2024-04-16 20:55:54
合計ジャッジ時間 7,600 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
12,160 KB
testcase_01 AC 89 ms
12,288 KB
testcase_02 AC 90 ms
12,288 KB
testcase_03 AC 89 ms
12,288 KB
testcase_04 AC 87 ms
12,032 KB
testcase_05 AC 89 ms
12,288 KB
testcase_06 AC 90 ms
12,160 KB
testcase_07 AC 88 ms
12,288 KB
testcase_08 AC 86 ms
12,160 KB
testcase_09 AC 88 ms
12,160 KB
testcase_10 AC 90 ms
12,032 KB
testcase_11 AC 87 ms
12,160 KB
testcase_12 AC 87 ms
12,288 KB
testcase_13 AC 87 ms
12,160 KB
testcase_14 AC 86 ms
12,160 KB
testcase_15 AC 89 ms
12,160 KB
testcase_16 AC 89 ms
12,160 KB
testcase_17 AC 89 ms
12,288 KB
testcase_18 AC 100 ms
12,416 KB
testcase_19 AC 112 ms
12,416 KB
testcase_20 AC 137 ms
13,056 KB
testcase_21 AC 87 ms
12,160 KB
testcase_22 AC 287 ms
16,640 KB
testcase_23 AC 498 ms
20,480 KB
testcase_24 AC 275 ms
16,768 KB
testcase_25 AC 498 ms
20,608 KB
testcase_26 AC 503 ms
20,608 KB
testcase_27 AC 490 ms
20,608 KB
testcase_28 AC 510 ms
20,480 KB
testcase_29 AC 495 ms
20,608 KB
testcase_30 AC 489 ms
20,608 KB
testcase_31 AC 480 ms
20,480 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N=gets.to_i
r=Float::INFINITY
t=0
c=[]
N.times{
	a,b=gets.split.map &:to_i
	t+=a
	c<<a+b
}
q1=[]
(1<<N/2).times{|i|
	s=0
	(N/2).times{|j|i[j]>0&&s+=c[j]}
	q1<<s
}
q1=q1.uniq.sort
q2=[]
(1<<(N-N/2)).times{|i|
	s=0
	(N-N/2).times{|j|i[j]>0&&s+=c[N/2+j]}
	q2<<s
}
q2=q2.uniq.sort
q1.each{|e|
	fidx=(0...q2.size).bsearch{|i|q2[i]>=t-e}||q2.size
	f_=([fidx-1,fidx]-[-1,q2.size]).map{|i|q2[i]}
	f_.each{|f|r=[r,(t-e-f).abs].min}
}
p r
0