結果

問題 No.240 ナイト散歩
ユーザー SagTokiSagToki
提出日時 2018-06-05 17:02:48
言語 Java19
(openjdk 21)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 1,600 bytes
コンパイル時間 5,721 ms
コンパイル使用メモリ 80,632 KB
実行使用メモリ 56,548 KB
最終ジャッジ日時 2023-09-12 22:26:21
合計ジャッジ時間 9,989 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,004 KB
testcase_01 AC 121 ms
55,792 KB
testcase_02 AC 121 ms
55,692 KB
testcase_03 AC 122 ms
55,692 KB
testcase_04 AC 120 ms
56,548 KB
testcase_05 AC 122 ms
55,708 KB
testcase_06 AC 121 ms
55,864 KB
testcase_07 AC 120 ms
55,628 KB
testcase_08 AC 121 ms
55,380 KB
testcase_09 AC 120 ms
55,800 KB
testcase_10 AC 120 ms
55,632 KB
testcase_11 AC 120 ms
55,696 KB
testcase_12 AC 120 ms
55,676 KB
testcase_13 AC 121 ms
55,760 KB
testcase_14 AC 121 ms
56,188 KB
testcase_15 AC 120 ms
55,628 KB
testcase_16 AC 119 ms
55,908 KB
testcase_17 AC 118 ms
55,696 KB
testcase_18 AC 120 ms
56,000 KB
testcase_19 AC 120 ms
56,008 KB
testcase_20 AC 120 ms
55,584 KB
testcase_21 AC 121 ms
55,684 KB
testcase_22 AC 118 ms
55,560 KB
testcase_23 AC 120 ms
55,696 KB
testcase_24 AC 118 ms
56,344 KB
testcase_25 AC 119 ms
55,408 KB
testcase_26 AC 118 ms
55,820 KB
testcase_27 AC 120 ms
55,684 KB
testcase_28 AC 118 ms
56,204 KB
testcase_29 AC 118 ms
55,692 KB
testcase_30 AC 121 ms
55,812 KB
testcase_31 AC 121 ms
55,820 KB
testcase_32 AC 121 ms
55,708 KB
testcase_33 AC 121 ms
55,704 KB
権限があれば一括ダウンロードができます

ソースコード

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(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;
    }
}
0