結果
問題 |
No.240 ナイト散歩
|
ユーザー |
![]() |
提出日時 | 2016-10-23 17:39:02 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 130 ms / 2,000 ms |
コード長 | 929 bytes |
コンパイル時間 | 2,020 ms |
コンパイル使用メモリ | 77,608 KB |
実行使用メモリ | 41,684 KB |
最終ジャッジ日時 | 2024-10-07 21:30:53 |
合計ジャッジ時間 | 7,305 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import java.util.*; import java.math.*; import java.text.*; public class Main { private static Scanner sc = new Scanner(System.in); private static int gx; private static int gy; public static void main(String[] args) throws Exception { gx = sc.nextInt(); gy = sc.nextInt(); if (move(0, 0, 0)) { System.out.println("YES"); } else { System.out.println("NO"); } } public static boolean move(int x, int y, int c) { if (c > 3) return false; if (x == gx && y == gy) return true; int[] dx = {1, 2, 2, 1, -1, -2, -2, -1}; int[] dy = {2, 1, -1, -2, -2, -1, 1, 2}; for (int i = 0;i < 8;i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (move(nx, ny, c+1)) { return true; } } return false; } }