結果

問題 No.240 ナイト散歩
コンテスト
ユーザー くわい
提出日時 2015-09-21 00:51:06
言語 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  
実行時間 436 ms / 2,000 ms
コード長 781 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,307 ms
コンパイル使用メモリ 269,396 KB
実行使用メモリ 65,368 KB
最終ジャッジ日時 2026-03-09 13:47:50
合計ジャッジ時間 25,349 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.Scanner

object Problem240 {
  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val x = sc.nextInt()
    val y = sc.nextInt()

    val result = proc(x, y, 3)
    println(result)
  }

  def proc(targetX: Int, targetY: Int, stepLimit: Int): String = {
    val dxy = List((-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2, 1))
    var found = false

    def procR(x: Int, y: Int, steps: Int): Unit = {
      if (x == targetX && y == targetY) {
        found = true
        return
      }

      if (steps == stepLimit || found) {
        return
      }

      for ((dx, dy) <- dxy) {
        procR(x + dx, y + dy, steps + 1)
      }
    }

    procR(0, 0, 0)

    if (found) {
      "YES"
    } else {
      "NO"
    }
  }
}
0