結果
問題 |
No.2355 Unhappy Back Dance
|
ユーザー |
![]() |
提出日時 | 2023-06-16 22:51:26 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 3,012 ms / 6,000 ms |
コード長 | 1,758 bytes |
コンパイル時間 | 2,783 ms |
コンパイル使用メモリ | 90,388 KB |
実行使用メモリ | 71,356 KB |
最終ジャッジ日時 | 2024-06-24 15:49:17 |
合計ジャッジ時間 | 55,794 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] x = new long[n]; long[] y = new long[n]; for (int i = 0; i < n; i++) { x[i] = sc.nextLong(); y[i] = sc.nextLong(); } sc.close(); int ans = 0; for (int i = 0; i < n; i++) { Map<String, List<Integer>> map = new HashMap<>(); for (int j = 0; j < n; j++) { if (j != i) { long dx = x[j] - x[i]; long dy = y[j] - y[i]; String s = "inf"; if (dx != 0) { if (dx < 0) { dx = -dx; dy = -dy; } long g = gcd(dx, Math.abs(dy)); dx /= g; dy /= g; s = dy + "/" + dx; } List<Integer> list = map.get(s); if (list == null) { list = new ArrayList<>(); map.put(s, list); } list.add(j); } } label: for (String s : map.keySet()) { List<Integer> list = map.get(s); if (list.size() < 2) { continue; } list.add(i); long[] z = s.equals("inf") ? y : x; int size = list.size(); Obj[] arr = new Obj[size]; for (int j = 0; j < size; j++) { Obj o = new Obj(); o.i = list.get(j); o.x = z[o.i]; arr[j] = o; } Arrays.sort(arr, (o1, o2) -> Long.compare(o1.x, o2.x)); for (int j = 0; j < size; j++) { Obj o = arr[j]; if (o.i == i && (j >= 2 || j < size - 2)) { ans++; break label; } } } } System.out.println(ans); } static class Obj { int i; long x; } static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } }