結果

問題 No.126 2基のエレベータ
ユーザー くわいくわい
提出日時 2015-09-25 00:39:38
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 901 ms / 5,000 ms
コード長 1,262 bytes
コンパイル時間 11,806 ms
コンパイル使用メモリ 253,492 KB
実行使用メモリ 63,116 KB
最終ジャッジ日時 2023-08-25 13:02:45
合計ジャッジ時間 38,779 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 832 ms
63,060 KB
testcase_01 AC 804 ms
62,512 KB
testcase_02 AC 805 ms
62,780 KB
testcase_03 AC 815 ms
62,468 KB
testcase_04 AC 815 ms
62,588 KB
testcase_05 AC 820 ms
62,532 KB
testcase_06 AC 817 ms
62,488 KB
testcase_07 AC 808 ms
62,628 KB
testcase_08 AC 856 ms
62,360 KB
testcase_09 AC 807 ms
62,812 KB
testcase_10 AC 782 ms
62,456 KB
testcase_11 AC 787 ms
62,504 KB
testcase_12 AC 852 ms
62,560 KB
testcase_13 AC 901 ms
62,668 KB
testcase_14 AC 897 ms
63,044 KB
testcase_15 AC 809 ms
63,096 KB
testcase_16 AC 819 ms
63,116 KB
testcase_17 AC 810 ms
62,840 KB
testcase_18 AC 804 ms
62,596 KB
testcase_19 AC 814 ms
62,480 KB
testcase_20 AC 831 ms
62,960 KB
testcase_21 AC 812 ms
62,604 KB
testcase_22 AC 802 ms
62,568 KB
testcase_23 AC 817 ms
62,544 KB
testcase_24 AC 818 ms
62,476 KB
testcase_25 AC 827 ms
62,580 KB
testcase_26 AC 851 ms
63,060 KB
testcase_27 AC 827 ms
63,080 KB
testcase_28 AC 824 ms
62,516 KB
testcase_29 AC 820 ms
62,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner

object Problem126 {

  def proc(a: Int, b: Int, s: Int): Int = {
    val distA = Math.abs(a - s)
    val distB = Math.abs(b - s)

    val (elevator, distToCurrentFloor) = (distA, distB) match {
      case _ if s == 1 => ("A", distA) // 1階にいる
      case (0, _) => ("A", 0) // 既にAが到着している
      case (_, 0) => ("B", 0) // 既にBが到着している
      case (a, b) if a <= b => ("A", a) // Aが優先
      case (a, b) if a > b => ("B", b) // Bが来る
    }

    val distToFloor0 = (elevator, distToCurrentFloor) match {
      case ("A", _) => s // Aが来たらそのまま乗っていけばよい
      case ("B", _) if a == 0 => s + 1 // Aが下の階にある場合は、Bで1階まで行って、そこからAに乗り継ぎ
      case ("B", _) if a < s => s // Aが下の階にある場合は、そこから乗り継ぎ
      case ("B", _) if a > s => Seq((a - s) + a, s + a - 1).min // Aが上の階にある場合、そこまで行くか、1階で下押すか。
    }

    distToCurrentFloor + distToFloor0
  }

  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val (a, b, s) = (sc.nextInt, sc.nextInt, sc.nextInt)
    val result = proc(a, b, s)
    println(result)
  }
}
0