結果

問題 No.240 ナイト散歩
ユーザー mobius_bkst
提出日時 2015-07-10 23:38:01
言語 Java11
(openjdk 11.0.5)
結果
AC  
実行時間 78 ms
コード長 1,478 Byte
コンパイル時間 3,463 ms
使用メモリ 48,440 KB
最終ジャッジ日時 2020-02-19 10:44:19

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
99_challenge01.txt AC 75 ms
44,656 KB
99_challenge02.txt AC 74 ms
44,392 KB
challenge01.txt AC 75 ms
44,776 KB
challenge02.txt AC 76 ms
44,496 KB
sample1.txt AC 75 ms
44,408 KB
sample2.txt AC 75 ms
44,412 KB
sample3.txt AC 78 ms
48,380 KB
sample4.txt AC 73 ms
44,580 KB
system_test1.txt AC 76 ms
44,460 KB
system_test2.txt AC 76 ms
44,656 KB
system_test3.txt AC 78 ms
48,432 KB
system_test4.txt AC 77 ms
46,528 KB
system_test5.txt AC 75 ms
44,484 KB
system_test6.txt AC 74 ms
44,384 KB
system_test7.txt AC 74 ms
44,412 KB
system_test8.txt AC 74 ms
44,416 KB
system_test9.txt AC 74 ms
44,652 KB
system_test10.txt AC 74 ms
44,524 KB
test1.txt AC 76 ms
44,428 KB
test2.txt AC 75 ms
44,480 KB
test3.txt AC 74 ms
44,420 KB
test4.txt AC 76 ms
44,844 KB
test5.txt AC 74 ms
44,656 KB
test6.txt AC 75 ms
44,520 KB
test7.txt AC 75 ms
44,580 KB
test8.txt AC 76 ms
44,476 KB
test9.txt AC 72 ms
44,424 KB
test10.txt AC 73 ms
46,384 KB
test11.txt AC 71 ms
44,520 KB
test12.txt AC 71 ms
44,544 KB
test13.txt AC 72 ms
48,440 KB
test14.txt AC 75 ms
44,540 KB
test15.txt AC 75 ms
44,544 KB
test16.txt AC 76 ms
44,408 KB
テストケース一括ダウンロード

ソースコード

diff #
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;
    }
}
0