結果

問題 No.1041 直線大学
ユーザー yomo3yomo3
提出日時 2020-05-08 12:28:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,023 bytes
コンパイル時間 1,798 ms
コンパイル使用メモリ 78,092 KB
実行使用メモリ 41,948 KB
最終ジャッジ日時 2024-04-28 00:15:36
合計ジャッジ時間 7,261 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
39,892 KB
testcase_01 AC 103 ms
40,036 KB
testcase_02 AC 98 ms
39,960 KB
testcase_03 AC 109 ms
41,216 KB
testcase_04 AC 108 ms
41,272 KB
testcase_05 AC 105 ms
41,400 KB
testcase_06 AC 106 ms
41,180 KB
testcase_07 AC 112 ms
40,548 KB
testcase_08 AC 101 ms
39,536 KB
testcase_09 AC 105 ms
40,144 KB
testcase_10 AC 132 ms
41,436 KB
testcase_11 AC 130 ms
41,180 KB
testcase_12 AC 138 ms
41,948 KB
testcase_13 AC 111 ms
41,212 KB
testcase_14 AC 120 ms
41,184 KB
testcase_15 AC 116 ms
41,312 KB
testcase_16 AC 119 ms
41,196 KB
testcase_17 AC 109 ms
41,396 KB
testcase_18 AC 114 ms
41,380 KB
testcase_19 AC 114 ms
41,056 KB
testcase_20 AC 110 ms
41,176 KB
testcase_21 AC 119 ms
41,488 KB
testcase_22 AC 103 ms
41,060 KB
testcase_23 AC 126 ms
41,368 KB
testcase_24 AC 120 ms
41,204 KB
testcase_25 AC 115 ms
41,192 KB
testcase_26 AC 118 ms
41,060 KB
testcase_27 AC 118 ms
41,532 KB
testcase_28 AC 107 ms
41,364 KB
testcase_29 AC 103 ms
40,940 KB
testcase_30 AC 104 ms
39,996 KB
testcase_31 AC 104 ms
41,216 KB
testcase_32 AC 104 ms
41,092 KB
testcase_33 AC 111 ms
40,992 KB
testcase_34 AC 106 ms
41,196 KB
testcase_35 AC 105 ms
41,232 KB
testcase_36 AC 106 ms
40,976 KB
testcase_37 AC 108 ms
41,316 KB
testcase_38 AC 128 ms
41,648 KB
testcase_39 AC 111 ms
41,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.awt.Point;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Point[] p = new Point[N];
        for (int i = 0; i < N; i++) {
            p[i] = new Point(sc.nextInt(), sc.nextInt());
        }

        int ans = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                int cnt = 2;
                for (int k = j + 1; k < N; k++) {
                    if (isCollinear(p[i], p[j], p[k])) {
                        cnt++;
                    }
                }
                ans = Math.max(ans, cnt);
            }
        }
        System.out.println(ans);
    }

    static boolean isCollinear(Point a, Point b, Point c) {
        // if (a.x == b.x && a.y == b.y) return false;
        if (a.x == b.x) return a.x == c.x;
        if (a.y == b.y) return a.y == c.y;
        return a.x*b.y-b.x*a.y + b.x*c.y-c.x*b.y + c.x*a.y-a.x*c.y == 0;
    }

}
0