結果

問題 No.343 手抜き工事のプロ
ユーザー code-devocode-devo
提出日時 2016-02-13 00:15:53
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 618 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 11,988 KB
実行使用メモリ 16,908 KB
最終ジャッジ日時 2023-10-22 03:45:29
合計ジャッジ時間 4,984 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
16,120 KB
testcase_01 AC 84 ms
16,120 KB
testcase_02 AC 89 ms
16,120 KB
testcase_03 AC 87 ms
16,120 KB
testcase_04 AC 86 ms
16,120 KB
testcase_05 AC 85 ms
16,120 KB
testcase_06 AC 85 ms
16,120 KB
testcase_07 AC 87 ms
16,380 KB
testcase_08 AC 89 ms
16,644 KB
testcase_09 AC 90 ms
16,908 KB
testcase_10 AC 84 ms
16,120 KB
testcase_11 AC 84 ms
16,120 KB
testcase_12 AC 91 ms
16,120 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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