結果

問題 No.343 手抜き工事のプロ
ユーザー code-devocode-devo
提出日時 2016-02-13 02:39:33
言語 Ruby
(3.3.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 478 bytes
コンパイル時間 128 ms
コンパイル使用メモリ 11,536 KB
実行使用メモリ 23,088 KB
最終ジャッジ日時 2023-08-27 01:32:03
合計ジャッジ時間 4,628 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,012 KB
testcase_01 AC 85 ms
15,124 KB
testcase_02 AC 87 ms
14,996 KB
testcase_03 AC 86 ms
15,304 KB
testcase_04 AC 85 ms
15,092 KB
testcase_05 AC 85 ms
15,116 KB
testcase_06 AC 85 ms
15,084 KB
testcase_07 AC 85 ms
15,236 KB
testcase_08 AC 87 ms
15,220 KB
testcase_09 AC 86 ms
15,288 KB
testcase_10 AC 85 ms
15,232 KB
testcase_11 AC 84 ms
15,060 KB
testcase_12 AC 85 ms
15,228 KB
testcase_13 AC 94 ms
15,600 KB
testcase_14 AC 89 ms
15,048 KB
testcase_15 AC 88 ms
15,120 KB
testcase_16 AC 84 ms
15,092 KB
testcase_17 AC 84 ms
15,004 KB
testcase_18 AC 84 ms
15,092 KB
testcase_19 AC 86 ms
15,288 KB
testcase_20 AC 94 ms
15,580 KB
testcase_21 AC 115 ms
17,552 KB
testcase_22 AC 127 ms
18,580 KB
testcase_23 AC 139 ms
19,836 KB
testcase_24 AC 168 ms
21,464 KB
testcase_25 AC 187 ms
22,980 KB
testcase_26 AC 183 ms
23,088 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
L = gets.to_i

xs = $stdin.read.split.map(&:to_i).reverse + [0]

begin
  ans = 0
  sum = 0
  cnt = 0
  for i in 0...xs.size do
    if i > 0 then
      raise "-1" if (xs[i-1] - xs[i]).abs >= L

      center = sum / cnt.to_f #重心
      ok = true
      ok &&= xs[i-1] < center && center < xs[i-1] + L
      ok &&= xs[i] < center && center < xs[i] + L
      ans += 1 unless ok
    end

    sum += xs[i] + L / 2.0
    cnt += 1
  end

  puts ans
rescue
  puts $!
end
0