結果

問題 No.343 手抜き工事のプロ
コンテスト
ユーザー norioc
提出日時 2026-01-07 02:25:05
言語 Scala(Beta)
(3.8.1)
コンパイル:
scalac _filename_
実行:
java -cp .:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala3-library_3/3.8.1/scala3-library_3-3.8.1.jar:/home/linuxbrew/.linuxbrew/Cellar/scala/3.8.1/libexec/maven2/org/scala-lang/scala-library/3.8.1/scala-library-3.8.1.jar _class_
結果
AC  
(最新)
TLE  
(最初)
実行時間 720 ms / 2,000 ms
コード長 802 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,226 ms
コンパイル使用メモリ 289,168 KB
実行使用メモリ 76,704 KB
最終ジャッジ日時 2026-03-09 20:17:19
合計ジャッジ時間 24,854 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import math._


object Main {
  def isInvalid(L: Int, xs: Array[Int]): Boolean = {
    for (i <- 0 to xs.length-2) {
      if (abs(xs(i) - xs(i+1)) >= L) return true
    }
    false
  }

  def calc(N: Int, L: Int, xs: Array[Int]): Int = {
    if (isInvalid(L, xs)) return -1

    var ans = 0
    var p = (xs.last + xs.last + L) / 2.0
    var cnt = 1
    for (i <- xs.length-2 to 0 by -1) {
      var t = p / cnt
      if (xs(i) < t && t < xs(i) + L && xs(i+1) < t && t < xs(i+1) + L) {
      }
      else ans += 1

      p += (xs(i) + xs(i) + L) / 2.0
      cnt += 1
    }
    ans
  }

  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt
    val L = sc.nextInt
    val xs = Array.fill(N-1)(sc.nextInt)
    println(calc(N, L, Array(0) ++ xs))
  }
}
0