結果

問題 No.1041 直線大学
ユーザー tentententen
提出日時 2021-03-17 13:47:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 2,154 bytes
コンパイル時間 2,069 ms
コンパイル使用メモリ 80,532 KB
実行使用メモリ 42,180 KB
最終ジャッジ日時 2024-04-28 00:18:31
合計ジャッジ時間 7,765 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
40,356 KB
testcase_01 AC 110 ms
41,120 KB
testcase_02 AC 107 ms
41,120 KB
testcase_03 AC 110 ms
41,236 KB
testcase_04 AC 107 ms
41,184 KB
testcase_05 AC 99 ms
40,208 KB
testcase_06 AC 103 ms
40,236 KB
testcase_07 AC 110 ms
40,332 KB
testcase_08 AC 118 ms
41,184 KB
testcase_09 AC 115 ms
41,400 KB
testcase_10 AC 159 ms
42,180 KB
testcase_11 AC 167 ms
41,688 KB
testcase_12 AC 143 ms
41,388 KB
testcase_13 AC 137 ms
41,652 KB
testcase_14 AC 126 ms
41,520 KB
testcase_15 AC 126 ms
41,456 KB
testcase_16 AC 123 ms
41,620 KB
testcase_17 AC 106 ms
40,556 KB
testcase_18 AC 110 ms
40,232 KB
testcase_19 AC 129 ms
41,636 KB
testcase_20 AC 110 ms
41,228 KB
testcase_21 AC 122 ms
41,336 KB
testcase_22 AC 109 ms
41,132 KB
testcase_23 AC 152 ms
41,796 KB
testcase_24 AC 127 ms
41,996 KB
testcase_25 AC 127 ms
41,196 KB
testcase_26 AC 114 ms
40,388 KB
testcase_27 AC 134 ms
41,632 KB
testcase_28 AC 110 ms
41,136 KB
testcase_29 AC 109 ms
41,076 KB
testcase_30 AC 95 ms
39,656 KB
testcase_31 AC 110 ms
41,124 KB
testcase_32 AC 100 ms
40,364 KB
testcase_33 AC 112 ms
41,180 KB
testcase_34 AC 102 ms
40,096 KB
testcase_35 AC 103 ms
40,208 KB
testcase_36 AC 99 ms
39,980 KB
testcase_37 AC 106 ms
41,104 KB
testcase_38 AC 138 ms
42,060 KB
testcase_39 AC 115 ms
41,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Point[] points = new Point[n];
        for (int i = 0; i < n; i++) {
            points[i] = new Point(sc.nextInt(), sc.nextInt());
        }
        int max = 2;
        for (int i = 0; i < n - 1; i++) {
            HashMap<Point, Integer> sums = new HashMap<>();
            for (int j = i + 1; j < n; j++) {
                Point p = points[i].get(points[j]);
                p.normalize();
                sums.put(p, sums.getOrDefault(p, 0) + 1);
            }
            for (int x : sums.values()) {
                max = Math.max(max, x + 1);
            }
        }
        System.out.println(max);
    }
    
    static class Point {
        int x;
        int y;
        
        public  Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
        
        public Point get(Point p) {
            return new Point(x - p.x, y - p.y);
        }
        
        public void normalize() {
            if (x == 0) {
                y = 1;
                return;
            }
            if (y == 0) {
                x = 1;
                return;
            }
            boolean isMinus = false;
            if (x < 0) {
                x *= -1;
                isMinus ^= true;
            }
            if (y < 0) {
                y *= -1;
                isMinus ^= true;
            }
            int gcd = getGCD(x, y);
            x /= gcd;
            y /= gcd;
            if (isMinus) {
                y *= -1;
            }
        }
        
        private int getGCD(int a, int b) {
            if (a % b == 0) {
                return b;
            } else {
                return getGCD(b, a % b);
            }
        }
        
        public int hashCode() {
            return x + y;
        }
        
        public boolean equals(Object o) {
            Point p = (Point)o;
            return p.x == x && p.y == y;
        }
        
        public String toString() {
            return x + ":" + y;
        }
    }
}
0