結果

問題 No.240 ナイト散歩
ユーザー jp_stejp_ste
提出日時 2016-03-01 16:30:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 1,325 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 76,728 KB
実行使用メモリ 41,380 KB
最終ジャッジ日時 2024-04-16 19:40:32
合計ジャッジ時間 7,759 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
41,220 KB
testcase_01 AC 132 ms
41,180 KB
testcase_02 AC 124 ms
39,860 KB
testcase_03 AC 135 ms
41,052 KB
testcase_04 AC 133 ms
41,148 KB
testcase_05 AC 135 ms
41,376 KB
testcase_06 AC 135 ms
41,252 KB
testcase_07 AC 135 ms
41,156 KB
testcase_08 AC 134 ms
41,256 KB
testcase_09 AC 134 ms
41,052 KB
testcase_10 AC 137 ms
41,276 KB
testcase_11 AC 136 ms
41,192 KB
testcase_12 AC 133 ms
41,324 KB
testcase_13 AC 134 ms
41,072 KB
testcase_14 AC 123 ms
40,084 KB
testcase_15 AC 131 ms
41,356 KB
testcase_16 AC 131 ms
41,020 KB
testcase_17 AC 135 ms
41,320 KB
testcase_18 AC 131 ms
41,380 KB
testcase_19 AC 134 ms
41,232 KB
testcase_20 AC 133 ms
41,044 KB
testcase_21 AC 134 ms
41,156 KB
testcase_22 AC 135 ms
41,228 KB
testcase_23 AC 135 ms
41,192 KB
testcase_24 AC 135 ms
41,296 KB
testcase_25 AC 135 ms
41,072 KB
testcase_26 AC 134 ms
41,356 KB
testcase_27 AC 134 ms
41,088 KB
testcase_28 AC 133 ms
41,272 KB
testcase_29 AC 134 ms
41,304 KB
testcase_30 AC 134 ms
41,060 KB
testcase_31 AC 137 ms
41,348 KB
testcase_32 AC 134 ms
41,052 KB
testcase_33 AC 133 ms
41,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    
    static int X, Y;
    static int dx[] = { -2, -2, -1, -1,  1, 1,  2, 2 };
    static int dy[] = { -1,  1, -2,  2, -2, 2, -1, 1 };
    
    public static void main(String[] args) {
        try (Scanner scan = new Scanner(System.in)) {
            X = scan.nextInt();
            Y = scan.nextInt();
            
            if(solve()) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
    
    static boolean solve() {
        int x = 0, y = 0;
        if(x == X && y == Y) return true;
  
        for(int i=0; i<dx.length; i++) {
            x += dx[i];
            y += dy[i];
            if(x == X && y == Y) return true;
            for(int j=0; j<dx.length; j++) {
                x += dx[j];
                y += dy[j];
                if(x == X && y == Y) return true;
                for(int k=0; k<dx.length; k++) {
                    x += dx[k];
                    y += dy[k];
                    if(x == X && y == Y) return true;
                    x -= dx[k];
                    y -= dy[k];
                }
                x -= dx[j];
                y -= dy[j];
            }
            x -= dx[i];
            y -= dy[i];
        }
        return false;
    }
}
0