結果

問題 No.240 ナイト散歩
ユーザー htensai
提出日時 2019-12-17 16:15:04
言語 Java
(openjdk 23)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,689 bytes
コンパイル時間 2,581 ms
コンパイル使用メモリ 79,720 KB
実行使用メモリ 37,100 KB
最終ジャッジ日時 2024-07-02 21:29:39
合計ジャッジ時間 5,689 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

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