結果

問題 No.370 道路の掃除
ユーザー cympfhcympfh
提出日時 2016-05-13 22:33:17
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 575 bytes
コンパイル時間 48 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-04-15 16:35:03
合計ジャッジ時間 4,027 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 98 ms
12,288 KB
testcase_02 AC 94 ms
12,288 KB
testcase_03 AC 89 ms
12,160 KB
testcase_04 AC 88 ms
12,416 KB
testcase_05 RE -
testcase_06 AC 87 ms
12,288 KB
testcase_07 AC 87 ms
12,288 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 AC 85 ms
12,288 KB
testcase_11 RE -
testcase_12 AC 89 ms
12,160 KB
testcase_13 RE -
testcase_14 AC 89 ms
12,160 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 90 ms
12,288 KB
testcase_20 RE -
testcase_21 AC 89 ms
12,288 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 89 ms
12,416 KB
testcase_25 AC 88 ms
12,288 KB
testcase_26 RE -
testcase_27 AC 87 ms
12,160 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 89 ms
12,416 KB
testcase_32 RE -
testcase_33 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n,m=gets.chomp.split.map(&:to_i)
ds = m.times.map{ gets.to_i }

xs = ds.select{|x| x < 0 }.map{|x| -x}.sort
ys = ds.select{|x| x > 0 }.sort

if ds.select{|x| x == 0}.length > 0
  n -= 1
end

ans = 1e10

if xs.size >= n
  ans = [ans, xs[n-1]].min
end
if ys.size >= n
  ans = [ans, ys[n-1]].min
end

for k in 0..xs.size do
  if k < n
    d = (k == 0 ? 0 : xs[k-1]) * 2 + (n==k ? 0 : ys[n-k-1])
    ans = [ans, d].min
  end
end

xs,ys = ys,xs

for k in 0..xs.size do
  if k < n
    d = (k == 0 ? 0 : xs[k-1]) * 2 + (n==k ? 0 : ys[n-k-1])
    ans = [ans, d].min
  end
end

p ans
0