結果

問題 No.240 ナイト散歩
ユーザー くわい
提出日時 2015-09-21 00:51:06
言語 Scala(Beta)
(3.6.2)
結果
AC  
実行時間 967 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 10,471 ms
コンパイル使用メモリ 262,108 KB
実行使用メモリ 63,668 KB
最終ジャッジ日時 2024-11-16 17:12:19
合計ジャッジ時間 41,934 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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