結果

問題 No.240 ナイト散歩
ユーザー SagTokiSagToki
提出日時 2018-06-05 16:53:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,599 bytes
コンパイル時間 3,660 ms
コンパイル使用メモリ 79,776 KB
実行使用メモリ 55,928 KB
最終ジャッジ日時 2023-09-12 22:25:57
合計ジャッジ時間 9,140 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,752 KB
testcase_01 AC 128 ms
55,840 KB
testcase_02 AC 127 ms
55,372 KB
testcase_03 AC 128 ms
55,928 KB
testcase_04 AC 125 ms
55,796 KB
testcase_05 AC 124 ms
55,576 KB
testcase_06 AC 127 ms
55,816 KB
testcase_07 AC 124 ms
55,528 KB
testcase_08 AC 125 ms
55,740 KB
testcase_09 AC 125 ms
55,708 KB
testcase_10 AC 127 ms
55,708 KB
testcase_11 AC 124 ms
54,464 KB
testcase_12 AC 127 ms
55,652 KB
testcase_13 AC 127 ms
55,860 KB
testcase_14 AC 122 ms
55,832 KB
testcase_15 AC 125 ms
55,504 KB
testcase_16 AC 125 ms
55,700 KB
testcase_17 AC 126 ms
55,908 KB
testcase_18 AC 125 ms
55,780 KB
testcase_19 AC 123 ms
55,760 KB
testcase_20 AC 125 ms
55,528 KB
testcase_21 AC 125 ms
55,732 KB
testcase_22 AC 127 ms
55,708 KB
testcase_23 AC 126 ms
55,824 KB
testcase_24 AC 126 ms
55,720 KB
testcase_25 AC 128 ms
55,856 KB
testcase_26 AC 127 ms
55,660 KB
testcase_27 AC 127 ms
55,548 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 125 ms
55,616 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(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