結果

問題 No.343 手抜き工事のプロ
ユーザー code-devo
提出日時 2016-02-13 00:15:53
言語 Ruby
(3.4.1)
結果
TLE  
実行時間 -
コード長 618 bytes
コンパイル時間 455 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 20,128 KB
最終ジャッジ日時 2024-09-22 05:08:56
合計ジャッジ時間 5,074 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 TLE * 1 -- * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:28: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

# テストケース通る気がしない!

n = gets.to_i
l = gets.to_i

if n == 1 then
  puts 0
  exit
end

def juushin(xs)
  sum = 0
  cnt = 0
  xs.each do |x, c|
    sum += x * c
    cnt += c
  end
  return sum / cnt.to_f + 0.5
end

xs = $stdin.read.split.map(&:to_i).reverse
xs << 0
ws = Hash.new{0}
ans = 0
for i in 0...xs.size do
  if i > 0 then
    if (xs[i-1] - xs[i]).abs >= l then
      puts -1
      exit
    end

    j = juushin(ws)
    ok = (xs[i-1] < j) && (j < xs[i-1] + l) && (xs[i] < j) && (j < xs[i] + l)

    ans += 1 unless ok
  end
  
  l.times do |o|
    ws[xs[i] + o] += 1
  end
end

puts ans
0