結果

問題 No.609 Noelちゃんと星々
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-03-13 09:09:26
言語 Ruby
(3.3.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 237 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 20,992 KB
最終ジャッジ日時 2024-04-29 00:08:11
合計ジャッジ時間 5,545 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
18,560 KB
testcase_01 AC 125 ms
15,104 KB
testcase_02 AC 114 ms
13,952 KB
testcase_03 AC 118 ms
14,592 KB
testcase_04 AC 105 ms
13,312 KB
testcase_05 AC 171 ms
20,096 KB
testcase_06 AC 158 ms
18,688 KB
testcase_07 AC 127 ms
16,000 KB
testcase_08 AC 99 ms
12,544 KB
testcase_09 AC 115 ms
14,080 KB
testcase_10 AC 148 ms
17,152 KB
testcase_11 AC 135 ms
16,640 KB
testcase_12 AC 154 ms
17,920 KB
testcase_13 AC 100 ms
12,928 KB
testcase_14 AC 97 ms
12,416 KB
testcase_15 AC 160 ms
18,816 KB
testcase_16 AC 171 ms
20,480 KB
testcase_17 AC 153 ms
18,560 KB
testcase_18 AC 113 ms
13,952 KB
testcase_19 AC 158 ms
18,560 KB
testcase_20 AC 173 ms
20,736 KB
testcase_21 AC 173 ms
20,736 KB
testcase_22 AC 173 ms
20,864 KB
testcase_23 AC 173 ms
20,992 KB
testcase_24 AC 174 ms
20,608 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:1: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument
Main.rb:6: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

def g (xs,m)
	return xs.inject(0){|sum,e|
		sum+(m-e).abs
	}
end
n=gets.to_i
xs=gets.split.map{|e| e.to_i}.sort

if xs.size==1
	puts 0
else
	d1=g(xs,xs[xs.size/2])
	d2=g(xs,xs[xs.size/2+1])
	if(d1<d2)
		puts d1
	else
		puts d2
	end
	
end
0