結果

問題 No.240 ナイト散歩
ユーザー くわいくわい
提出日時 2015-09-21 00:51:06
言語 Scala(Beta)
(3.4.0)
結果
AC  
実行時間 865 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 8,420 ms
コンパイル使用メモリ 245,576 KB
実行使用メモリ 63,844 KB
最終ジャッジ日時 2024-04-28 05:18:47
合計ジャッジ時間 38,515 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 855 ms
63,492 KB
testcase_01 AC 854 ms
63,488 KB
testcase_02 AC 852 ms
63,832 KB
testcase_03 AC 855 ms
63,608 KB
testcase_04 AC 865 ms
63,680 KB
testcase_05 AC 842 ms
63,428 KB
testcase_06 AC 848 ms
63,608 KB
testcase_07 AC 820 ms
63,660 KB
testcase_08 AC 847 ms
63,396 KB
testcase_09 AC 865 ms
63,552 KB
testcase_10 AC 853 ms
63,620 KB
testcase_11 AC 848 ms
63,432 KB
testcase_12 AC 836 ms
63,632 KB
testcase_13 AC 849 ms
63,632 KB
testcase_14 AC 850 ms
63,788 KB
testcase_15 AC 838 ms
63,672 KB
testcase_16 AC 849 ms
63,720 KB
testcase_17 AC 836 ms
63,844 KB
testcase_18 AC 851 ms
63,624 KB
testcase_19 AC 836 ms
63,632 KB
testcase_20 AC 855 ms
63,588 KB
testcase_21 AC 842 ms
63,584 KB
testcase_22 AC 839 ms
63,728 KB
testcase_23 AC 844 ms
63,660 KB
testcase_24 AC 847 ms
63,652 KB
testcase_25 AC 843 ms
63,572 KB
testcase_26 AC 852 ms
63,704 KB
testcase_27 AC 851 ms
63,444 KB
testcase_28 AC 833 ms
63,532 KB
testcase_29 AC 819 ms
63,696 KB
testcase_30 AC 822 ms
63,668 KB
testcase_31 AC 826 ms
63,680 KB
testcase_32 AC 836 ms
63,512 KB
testcase_33 AC 844 ms
63,492 KB
権限があれば一括ダウンロードができます

ソースコード

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