結果

問題 No.240 ナイト散歩
ユーザー mobius_bkstmobius_bkst
提出日時 2015-07-10 23:38:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,478 bytes
コンパイル時間 3,386 ms
コンパイル使用メモリ 80,520 KB
実行使用メモリ 50,456 KB
最終ジャッジ日時 2024-04-16 19:29:22
合計ジャッジ時間 6,245 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
50,288 KB
testcase_01 AC 54 ms
50,284 KB
testcase_02 AC 54 ms
50,428 KB
testcase_03 AC 55 ms
50,244 KB
testcase_04 AC 55 ms
49,864 KB
testcase_05 AC 55 ms
50,168 KB
testcase_06 AC 55 ms
50,276 KB
testcase_07 AC 54 ms
50,340 KB
testcase_08 AC 56 ms
50,028 KB
testcase_09 AC 55 ms
50,184 KB
testcase_10 AC 55 ms
50,456 KB
testcase_11 AC 56 ms
50,160 KB
testcase_12 AC 54 ms
50,288 KB
testcase_13 AC 54 ms
50,296 KB
testcase_14 AC 56 ms
50,356 KB
testcase_15 AC 55 ms
50,112 KB
testcase_16 AC 55 ms
50,276 KB
testcase_17 AC 54 ms
50,264 KB
testcase_18 AC 55 ms
50,324 KB
testcase_19 AC 54 ms
50,312 KB
testcase_20 AC 55 ms
50,324 KB
testcase_21 AC 54 ms
49,904 KB
testcase_22 AC 55 ms
50,304 KB
testcase_23 AC 55 ms
50,300 KB
testcase_24 AC 56 ms
50,364 KB
testcase_25 AC 54 ms
50,328 KB
testcase_26 AC 55 ms
50,292 KB
testcase_27 AC 55 ms
50,420 KB
testcase_28 AC 55 ms
50,240 KB
testcase_29 AC 55 ms
49,896 KB
testcase_30 AC 55 ms
50,032 KB
testcase_31 AC 54 ms
50,332 KB
testcase_32 AC 56 ms
50,244 KB
testcase_33 AC 56 ms
50,300 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