結果

問題 No.240 ナイト散歩
ユーザー htensaihtensai
提出日時 2019-12-17 16:15:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,689 bytes
コンパイル時間 2,846 ms
コンパイル使用メモリ 75,880 KB
実行使用メモリ 50,504 KB
最終ジャッジ日時 2023-09-15 19:42:03
合計ジャッジ時間 5,941 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
50,228 KB
testcase_01 AC 47 ms
50,056 KB
testcase_02 AC 46 ms
50,068 KB
testcase_03 AC 47 ms
50,504 KB
testcase_04 AC 46 ms
50,244 KB
testcase_05 AC 46 ms
50,244 KB
testcase_06 AC 46 ms
49,924 KB
testcase_07 AC 46 ms
49,964 KB
testcase_08 AC 47 ms
50,076 KB
testcase_09 AC 46 ms
50,292 KB
testcase_10 AC 46 ms
48,040 KB
testcase_11 AC 46 ms
50,184 KB
testcase_12 AC 46 ms
50,272 KB
testcase_13 AC 46 ms
49,944 KB
testcase_14 AC 46 ms
50,076 KB
testcase_15 AC 46 ms
50,292 KB
testcase_16 AC 46 ms
50,200 KB
testcase_17 AC 45 ms
50,240 KB
testcase_18 AC 46 ms
50,240 KB
testcase_19 AC 46 ms
50,200 KB
testcase_20 AC 46 ms
50,332 KB
testcase_21 AC 46 ms
49,988 KB
testcase_22 AC 45 ms
48,508 KB
testcase_23 AC 46 ms
49,980 KB
testcase_24 AC 46 ms
50,184 KB
testcase_25 AC 45 ms
50,176 KB
testcase_26 AC 45 ms
50,340 KB
testcase_27 AC 45 ms
50,012 KB
testcase_28 AC 45 ms
50,072 KB
testcase_29 AC 47 ms
50,324 KB
testcase_30 AC 46 ms
50,032 KB
testcase_31 AC 45 ms
49,960 KB
testcase_32 AC 46 ms
49,928 KB
testcase_33 AC 45 ms
49,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 2);
        int x = Integer.parseInt(first[0]);
        int y = Integer.parseInt(first[1]);
        HashSet<Point> cur = new HashSet<>();
        cur.add(new Point(0, 0));
        for (int i = 0; i < 3; i++) {
            HashSet<Point> next = new HashSet<>();
            for (Point p : cur) {
                next.add(p);
                next.add(new Point(p.x + 1, p.y + 2));
                next.add(new Point(p.x - 1, p.y + 2));
                next.add(new Point(p.x + 1, p.y - 2));
                next.add(new Point(p.x - 1, p.y - 2));
                next.add(new Point(p.x + 2, p.y + 1));
                next.add(new Point(p.x - 2, p.y + 1));
                next.add(new Point(p.x + 2, p.y - 1));
                next.add(new Point(p.x - 2, p.y - 1));
            }
            cur = next;
        }
        if (cur.contains(new Point(x, y))) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
    
    static class Point {
        int x;
        int y;
        
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
        
        public int hashCode() {
            return x + y;
        }
        
        public boolean equals(Object o) {
            Point p = (Point) o;
            return x == p.x && y == p.y;
        }
        
        public String toString() {
            return x + ":" + y;
        }
    }
}
0