結果

問題 No.240 ナイト散歩
ユーザー SagToki
提出日時 2018-06-05 16:53:46
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,599 bytes
コンパイル時間 3,831 ms
コンパイル使用メモリ 79,264 KB
実行使用メモリ 56,340 KB
最終ジャッジ日時 2024-06-30 09:55:50
合計ジャッジ時間 9,566 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 25 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

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(X == NowX && Y == NowY){
            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;
    }
}
0