結果
問題 | No.240 ナイト散歩 |
ユーザー | mobius_bkst |
提出日時 | 2015-07-10 23:38:01 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 1,478 bytes |
コンパイル時間 | 3,699 ms |
コンパイル使用メモリ | 78,384 KB |
実行使用メモリ | 50,456 KB |
最終ジャッジ日時 | 2024-10-07 20:52:39 |
合計ジャッジ時間 | 6,550 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; public class No240 { static int[] moveX = { -2, -2, -1, -1, +1, +1, +2, +2 }; static int[] moveY = { -1, +1, -2, +2, -2, +2, -1, +1 }; static int X; static int Y; public static void main(String[] args) { try { BufferedReader br = new BufferedReader(new InputStreamReader( System.in)); int[] a = strToIntArray(br.readLine()); X = a[0]; Y = a[1]; String ans = dfs(0, 0, 0); System.out.println(ans); } catch (Exception e) { e.printStackTrace(); System.err.println("Error:" + e.getMessage()); } } static String dfs(int currentX, int currentY, int count) { if (3 < count) { return "NO"; } if (currentX == X && currentY == Y) { return "YES"; } count++; for (int i = 0; i < moveX.length; i++) { if (dfs(currentX + moveX[i], currentY + moveY[i], count).equals( "YES")) { return "YES"; } } return "NO"; } static int[] strToIntArray(String S) { String[] strArray = S.split(" "); int[] intArray = new int[strArray.length]; for (int i = 0; i < strArray.length; i++) { intArray[i] = Integer.parseInt(strArray[i]); } return intArray; } }