結果

問題 No.240 ナイト散歩
ユーザー atkrymatkrym
提出日時 2016-10-23 17:39:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 929 bytes
コンパイル時間 2,414 ms
コンパイル使用メモリ 77,572 KB
実行使用メモリ 41,888 KB
最終ジャッジ日時 2024-04-16 19:44:03
合計ジャッジ時間 8,166 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
41,708 KB
testcase_01 AC 129 ms
41,720 KB
testcase_02 AC 131 ms
41,536 KB
testcase_03 AC 131 ms
41,488 KB
testcase_04 AC 130 ms
41,444 KB
testcase_05 AC 122 ms
41,580 KB
testcase_06 AC 130 ms
41,504 KB
testcase_07 AC 120 ms
40,156 KB
testcase_08 AC 130 ms
41,308 KB
testcase_09 AC 134 ms
41,156 KB
testcase_10 AC 132 ms
41,704 KB
testcase_11 AC 133 ms
41,328 KB
testcase_12 AC 121 ms
40,056 KB
testcase_13 AC 136 ms
41,592 KB
testcase_14 AC 138 ms
41,424 KB
testcase_15 AC 138 ms
41,256 KB
testcase_16 AC 140 ms
41,568 KB
testcase_17 AC 133 ms
41,864 KB
testcase_18 AC 129 ms
41,488 KB
testcase_19 AC 131 ms
41,496 KB
testcase_20 AC 117 ms
41,716 KB
testcase_21 AC 118 ms
41,704 KB
testcase_22 AC 133 ms
41,408 KB
testcase_23 AC 130 ms
41,404 KB
testcase_24 AC 129 ms
41,472 KB
testcase_25 AC 129 ms
41,460 KB
testcase_26 AC 133 ms
41,888 KB
testcase_27 AC 135 ms
41,524 KB
testcase_28 AC 128 ms
41,480 KB
testcase_29 AC 133 ms
41,628 KB
testcase_30 AC 134 ms
41,608 KB
testcase_31 AC 134 ms
41,392 KB
testcase_32 AC 133 ms
41,304 KB
testcase_33 AC 132 ms
41,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;
import java.text.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    private static int gx;
    private static int gy;
    public static void main(String[] args) throws Exception {
        gx = sc.nextInt();
        gy = sc.nextInt();
        
        if (move(0, 0, 0)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
    
    public static boolean move(int x, int y, int c) {
        if (c > 3) return false;
        if (x == gx && y == gy) return true;
        
        int[] dx = {1, 2, 2, 1, -1, -2, -2, -1};
        int[] dy = {2, 1, -1, -2, -2, -1, 1, 2};
        
        for (int i = 0;i < 8;i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];

            if (move(nx, ny, c+1)) {
                return true;
            }
        }
        return false;
    }
}
0