結果
問題 | No.240 ナイト散歩 |
ユーザー |
![]() |
提出日時 | 2018-06-05 17:02:48 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 134 ms / 2,000 ms |
コード長 | 1,600 bytes |
コンパイル時間 | 3,584 ms |
コンパイル使用メモリ | 80,004 KB |
実行使用メモリ | 54,700 KB |
最終ジャッジ日時 | 2024-06-30 09:56:07 |
合計ジャッジ時間 | 9,266 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import java.util.Scanner; import java.util.InputMismatchException; public class KnightWalk { static Scanner scanner = new Scanner(System.in); public static void main(String[] args){ int X = Input(-1000000000 , 1000000000); int Y = Input(-1000000000 , 1000000000); scanner.close(); boolean Answer = Judge(X , Y , 0 , 0 , 0); if(Answer){ System.out.println("YES"); }else{ System.out.println("NO"); } } public static int Input(int Min , int Max){ int Number = scanner.nextInt(); try{ if(Number < Min || Number > Max){ System.out.println(Min + "以上" + Max + "以下で入力してください"); System.exit(0); } }catch(InputMismatchException e){ System.out.println("数字を入力してください"); System.exit(0); }catch(Exception E){ System.out.println("想定外のエラーです"); System.exit(0); } return Number; } public static boolean Judge(int X , int Y , int NowX , int NowY , int Count){ int[] Xwidth = {1,2,2,1,-1,-2,-2,-1}; int[] Ywidth = {2,1,-1,-2,-2,-1,1,2}; if(NowX == X && NowY == Y){ return true; } if(Count == 3){ return false; } for(int i = 0 ; i < Xwidth.length ; i++){ if(Judge(X , Y , NowX + Xwidth[i] , NowY + Ywidth[i] , Count + 1)){ return true; } } return false; } }