結果

問題 No.240 ナイト散歩
ユーザー mobius_bkst
提出日時 2015-07-10 23:38:01
言語 Java8
(openjdk 1.8.0.222)
結果
AC  
実行時間 87 ms
コード長 1,478 Byte
コンパイル時間 2,427 ms
使用メモリ 19,196 KB
最終ジャッジ日時 2019-10-06 00:36:20

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
99_challenge01.txt AC 80 ms
19,196 KB
99_challenge02.txt AC 81 ms
19,196 KB
challenge01.txt AC 79 ms
19,192 KB
challenge02.txt AC 86 ms
19,192 KB
sample1.txt AC 80 ms
19,192 KB
sample2.txt AC 85 ms
19,196 KB
sample3.txt AC 81 ms
19,196 KB
sample4.txt AC 83 ms
19,184 KB
system_test1.txt AC 82 ms
19,196 KB
system_test2.txt AC 82 ms
19,196 KB
system_test3.txt AC 82 ms
19,196 KB
system_test4.txt AC 82 ms
19,196 KB
system_test5.txt AC 81 ms
19,192 KB
system_test6.txt AC 80 ms
19,196 KB
system_test7.txt AC 80 ms
19,192 KB
system_test8.txt AC 82 ms
19,192 KB
system_test9.txt AC 82 ms
19,196 KB
system_test10.txt AC 82 ms
19,192 KB
test1.txt AC 81 ms
19,192 KB
test2.txt AC 86 ms
19,196 KB
test3.txt AC 83 ms
19,192 KB
test4.txt AC 80 ms
19,196 KB
test5.txt AC 86 ms
19,192 KB
test6.txt AC 80 ms
19,196 KB
test7.txt AC 85 ms
19,192 KB
test8.txt AC 81 ms
19,196 KB
test9.txt AC 81 ms
19,192 KB
test10.txt AC 81 ms
19,196 KB
test11.txt AC 81 ms
19,192 KB
test12.txt AC 82 ms
19,196 KB
test13.txt AC 81 ms
19,192 KB
test14.txt AC 82 ms
19,192 KB
test15.txt AC 81 ms
19,192 KB
test16.txt AC 87 ms
19,192 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