結果

問題 No.1041 直線大学
ユーザー silviasetitechsilviasetitech
提出日時 2020-05-13 20:28:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,964 bytes
コンパイル時間 2,459 ms
コンパイル使用メモリ 80,044 KB
実行使用メモリ 59,324 KB
最終ジャッジ日時 2023-10-12 17:03:51
合計ジャッジ時間 9,550 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,172 KB
testcase_01 AC 127 ms
55,788 KB
testcase_02 AC 127 ms
55,884 KB
testcase_03 AC 130 ms
55,932 KB
testcase_04 AC 128 ms
55,912 KB
testcase_05 AC 130 ms
55,896 KB
testcase_06 AC 129 ms
55,720 KB
testcase_07 AC 135 ms
55,436 KB
testcase_08 WA -
testcase_09 AC 134 ms
54,180 KB
testcase_10 AC 163 ms
57,932 KB
testcase_11 AC 162 ms
58,124 KB
testcase_12 AC 175 ms
58,424 KB
testcase_13 AC 137 ms
55,460 KB
testcase_14 WA -
testcase_15 AC 140 ms
55,464 KB
testcase_16 AC 163 ms
58,320 KB
testcase_17 WA -
testcase_18 AC 146 ms
57,488 KB
testcase_19 WA -
testcase_20 AC 127 ms
55,672 KB
testcase_21 AC 146 ms
57,752 KB
testcase_22 AC 127 ms
55,564 KB
testcase_23 AC 182 ms
58,532 KB
testcase_24 WA -
testcase_25 AC 147 ms
58,152 KB
testcase_26 AC 134 ms
55,392 KB
testcase_27 AC 137 ms
55,972 KB
testcase_28 AC 125 ms
55,344 KB
testcase_29 AC 125 ms
56,048 KB
testcase_30 AC 126 ms
55,460 KB
testcase_31 AC 127 ms
56,296 KB
testcase_32 AC 127 ms
55,796 KB
testcase_33 AC 126 ms
55,664 KB
testcase_34 AC 127 ms
55,940 KB
testcase_35 AC 126 ms
55,788 KB
testcase_36 AC 127 ms
55,712 KB
testcase_37 AC 126 ms
55,904 KB
testcase_38 AC 172 ms
58,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Objects;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ChokusenUniv solver = new ChokusenUniv();
        solver.solve(1, in, out);
        out.close();
    }

    static class ChokusenUniv {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            Vec2i[] v = new Vec2i[n];
            int max = 2;
            for (int i = 0; i < n; i++) {
                v[i] = new Vec2i(in.nextInt(), in.nextInt());
            }

            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    // i-> j
                    int cnt = 0;
                    Vec2i dif = new Vec2i(v[i].x - v[i + 1].x, v[i].y - v[i + 1].y);
                    int gcd = (int) MathUtil.gcd(Math.abs(dif.x), Math.abs(dif.y));
                    dif.x /= gcd;
                    dif.y /= gcd;

                    for (int k = 0; k < n; k++) {
                        Vec2i diff = new Vec2i(v[k].x - v[i].x, v[k].y - v[i].y);
                        if (dif.x == 0) {
                            if (diff.x == 0) cnt++;
                            continue;
                        }
                        if (dif.y == 0) {
                            if (diff.y == 0) cnt++;
                            continue;
                        }

                        if (diff.x / dif.x == diff.y / dif.y && diff.x % dif.x == 0 && diff.y % dif.y == 0)
                            cnt++;
                    }

                    max = Math.max(max, cnt);
                }
            }

            out.println(max);

        }

    }

    static class MathUtil {
        public static long gcd(long a, long b) {
            if (b == 0) return a;
            return a % b == 0 ? b : gcd(b, a % b);
        }

    }

    static class Vec2i {
        public int x;
        public int y;

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

        public String toString() {
            return "Vec2i{" +
                    "x=" + x +
                    ", y=" + y +
                    '}';
        }

        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Vec2i vec2i = (Vec2i) o;
            return x == vec2i.x &&
                    y == vec2i.y;
        }

        public int hashCode() {
            return Objects.hash(x, y);
        }

    }
}

0