結果
問題 |
No.1041 直線大学
|
ユーザー |
![]() |
提出日時 | 2020-05-13 20:28:48 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,964 bytes |
コンパイル時間 | 2,418 ms |
コンパイル使用メモリ | 79,860 KB |
実行使用メモリ | 45,332 KB |
最終ジャッジ日時 | 2024-09-14 15:38:42 |
合計ジャッジ時間 | 9,847 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 WA * 5 |
ソースコード
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); } } }