結果

問題 No.837 Noelちゃんと星々2
ユーザー pekempeypekempey
提出日時 2019-06-15 03:04:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 328 bytes
コンパイル時間 61 ms
コンパイル使用メモリ 11,296 KB
実行使用メモリ 29,036 KB
最終ジャッジ日時 2023-09-02 07:24:00
合計ジャッジ時間 5,631 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 224 ms
28,764 KB
testcase_01 AC 226 ms
28,876 KB
testcase_02 AC 227 ms
28,980 KB
testcase_03 AC 225 ms
28,780 KB
testcase_04 AC 227 ms
29,036 KB
testcase_05 AC 227 ms
29,020 KB
testcase_06 AC 228 ms
28,856 KB
testcase_07 AC 228 ms
28,952 KB
testcase_08 AC 231 ms
29,032 KB
testcase_09 AC 78 ms
15,032 KB
testcase_10 AC 77 ms
15,264 KB
testcase_11 AC 81 ms
15,048 KB
testcase_12 AC 78 ms
15,092 KB
testcase_13 AC 80 ms
15,264 KB
testcase_14 AC 78 ms
15,308 KB
testcase_15 AC 79 ms
15,132 KB
testcase_16 AC 79 ms
15,156 KB
testcase_17 AC 77 ms
15,140 KB
testcase_18 AC 78 ms
15,088 KB
testcase_19 AC 79 ms
15,340 KB
testcase_20 AC 78 ms
15,240 KB
testcase_21 AC 78 ms
15,172 KB
testcase_22 AC 78 ms
15,132 KB
testcase_23 AC 78 ms
15,032 KB
testcase_24 AC 77 ms
15,136 KB
testcase_25 AC 77 ms
15,312 KB
testcase_26 AC 77 ms
15,092 KB
testcase_27 AC 78 ms
15,052 KB
testcase_28 AC 78 ms
15,152 KB
testcase_29 AC 77 ms
15,336 KB
testcase_30 AC 77 ms
15,176 KB
testcase_31 AC 79 ms
15,160 KB
testcase_32 AC 77 ms
15,204 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
a = gets.split.map(&:to_i).sort
if a[0] == a[-1]
  puts 1
  exit
end

s = [0] * (n+1)
n.times do |i|
  s[i+1] = s[i] + a[i]
end
ans = 10**100
(1..n-1).each do |i|
  f = ->(l, r) do
    m1 = (l + r) / 2
    m2 = (l + r + 1) / 2
    (s[r]-s[m2])-(s[m1]-s[l])
  end
  ans = [ans, f.(0,i) + f.(i,n)].min
end

puts ans
0