結果

問題 No.202 1円玉投げ
ユーザー thorikawathorikawa
提出日時 2015-05-03 23:59:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,150 ms / 5,000 ms
コード長 2,471 bytes
コンパイル時間 2,363 ms
コンパイル使用メモリ 80,132 KB
実行使用メモリ 89,912 KB
最終ジャッジ日時 2023-08-23 21:45:38
合計ジャッジ時間 27,179 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,031 ms
86,696 KB
testcase_01 AC 1,150 ms
87,424 KB
testcase_02 AC 123 ms
56,056 KB
testcase_03 AC 125 ms
55,748 KB
testcase_04 AC 126 ms
56,080 KB
testcase_05 AC 304 ms
60,008 KB
testcase_06 AC 968 ms
86,148 KB
testcase_07 AC 995 ms
89,240 KB
testcase_08 AC 992 ms
86,860 KB
testcase_09 AC 692 ms
71,444 KB
testcase_10 AC 474 ms
62,804 KB
testcase_11 AC 635 ms
69,212 KB
testcase_12 AC 655 ms
69,040 KB
testcase_13 AC 487 ms
63,336 KB
testcase_14 AC 321 ms
60,460 KB
testcase_15 AC 690 ms
71,000 KB
testcase_16 AC 974 ms
89,912 KB
testcase_17 AC 998 ms
89,144 KB
testcase_18 AC 932 ms
88,268 KB
testcase_19 AC 662 ms
70,244 KB
testcase_20 AC 902 ms
84,028 KB
testcase_21 AC 638 ms
69,420 KB
testcase_22 AC 212 ms
58,472 KB
testcase_23 AC 203 ms
58,532 KB
testcase_24 AC 203 ms
58,552 KB
testcase_25 AC 204 ms
58,628 KB
testcase_26 AC 207 ms
58,912 KB
testcase_27 AC 216 ms
58,976 KB
testcase_28 AC 207 ms
58,552 KB
testcase_29 AC 209 ms
59,264 KB
testcase_30 AC 205 ms
58,808 KB
testcase_31 AC 199 ms
58,824 KB
testcase_32 AC 207 ms
58,468 KB
testcase_33 AC 206 ms
58,588 KB
testcase_34 AC 208 ms
58,828 KB
testcase_35 AC 998 ms
89,744 KB
testcase_36 AC 996 ms
86,840 KB
testcase_37 AC 1,047 ms
86,780 KB
testcase_38 AC 1,013 ms
86,524 KB
testcase_39 AC 173 ms
56,432 KB
testcase_40 AC 167 ms
56,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static class Point {
        int x;
        int y;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        double dist(Point o) {
            return Math.sqrt((this.x - o.x) * (this.x - o.x) + (this.y - o.y) * (this.y - o.y));
        }

        @Override
        public String toString() {
            return "(" + this.x + ", " + this.y + ")";
        }
    }

    static int getId(int x, int y) {
        return x * 1001 + y;
    }

    static int[] dirx = new int[]{0, 1, 0, -1, 0, 1, 1, -1, -1};
    static int[] diry = new int[]{0, 0, 1, 0, -1, 1, -1, 1, -1};

    public static void main(String[] argv) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int res = 0;
        Map<Integer, List<Point>> data = new HashMap<Integer, List<Point>>();
        for (int i = 0; i < n; i++) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            Point p = new Point(x, y);
            x /= 20;
            y /= 20;
            boolean overwrap = false;
            for (int j = 0; j < dirx.length; j++) {
                int nx = dirx[j] + x;
                int ny = diry[j] + y;
                if (nx < 0 || ny < 0 || nx > 1001 || ny > 1001) continue;
                int newKey = getId(nx, ny);
                if (data.containsKey(newKey)) {
                    List<Point> points = data.get(newKey);
                    for (Point p2 : points) {
//                        System.out.println("compare:" + p.toString() + " : " + p2.toString());
                        if (p.dist(p2) < 20) {
//                            System.out.println("overwrap!!");
                            overwrap = true;
                            break;
                        }
                    }
                }
                if (overwrap) {
                    break;
                }
            }
            if (!overwrap) {
                List<Point> list;
                int id = getId(x, y);
                if (data.containsKey(id)) {
                    list = data.get(id);
                } else {
                    list = new ArrayList<Point>();
                    data.put(id, list);
                }
//                System.out.println("add:" + id + ":" + p.toString());
                res++;
                list.add(p);
            }
        }
        System.out.println(res);
    }
}
0