結果

問題 No.275 中央値を求めよ
ユーザー fungsi
提出日時 2025-09-09 20:21:10
言語 Crystal
(1.14.0)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 326 bytes
コンパイル時間 12,225 ms
コンパイル使用メモリ 312,080 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-09 20:21:24
合計ジャッジ時間 13,934 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

n = gets.to_s.to_i
a = gets.to_s.split.map(&.to_i)

(1...n).each do |i|
  temp_itr = i - 1
  t = a[i]
  while 0 <= temp_itr && t <= a[temp_itr]
    a[temp_itr + 1] = a[temp_itr]
    a[temp_itr] = t
    temp_itr -= 1
  end
end

if a.size % 2 == 1
  puts a[n // 2]
else
  h = n // 2
  r = (a[h] + a[h - 1]).to_f
  puts r / 2
end
0