結果

問題 No.2355 Unhappy Back Dance
ユーザー ks2mks2m
提出日時 2023-06-16 22:51:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,470 ms / 6,000 ms
コード長 1,758 bytes
コンパイル時間 3,619 ms
コンパイル使用メモリ 88,720 KB
実行使用メモリ 74,280 KB
最終ジャッジ日時 2023-09-06 21:29:31
合計ジャッジ時間 49,471 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
56,796 KB
testcase_01 AC 139 ms
56,716 KB
testcase_02 AC 146 ms
57,284 KB
testcase_03 AC 113 ms
54,132 KB
testcase_04 AC 133 ms
57,108 KB
testcase_05 AC 133 ms
57,004 KB
testcase_06 AC 597 ms
64,992 KB
testcase_07 AC 691 ms
66,384 KB
testcase_08 AC 735 ms
66,356 KB
testcase_09 AC 797 ms
66,272 KB
testcase_10 AC 1,771 ms
71,372 KB
testcase_11 AC 1,450 ms
71,580 KB
testcase_12 AC 1,802 ms
67,152 KB
testcase_13 AC 1,694 ms
66,728 KB
testcase_14 AC 1,583 ms
74,280 KB
testcase_15 AC 112 ms
55,856 KB
testcase_16 AC 2,336 ms
65,088 KB
testcase_17 AC 2,469 ms
66,648 KB
testcase_18 AC 2,347 ms
65,468 KB
testcase_19 AC 2,447 ms
65,904 KB
testcase_20 AC 2,470 ms
66,284 KB
testcase_21 AC 1,315 ms
65,204 KB
testcase_22 AC 618 ms
64,488 KB
testcase_23 AC 610 ms
66,124 KB
testcase_24 AC 2,254 ms
65,664 KB
testcase_25 AC 1,466 ms
65,288 KB
testcase_26 AC 1,462 ms
65,656 KB
testcase_27 AC 1,341 ms
65,760 KB
testcase_28 AC 261 ms
59,472 KB
testcase_29 AC 355 ms
60,296 KB
testcase_30 AC 2,035 ms
64,016 KB
testcase_31 AC 1,644 ms
65,480 KB
testcase_32 AC 530 ms
64,264 KB
testcase_33 AC 1,173 ms
65,624 KB
testcase_34 AC 216 ms
59,760 KB
testcase_35 AC 272 ms
59,328 KB
testcase_36 AC 1,472 ms
66,280 KB
testcase_37 AC 909 ms
65,660 KB
testcase_38 AC 1,022 ms
64,292 KB
testcase_39 AC 1,012 ms
65,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
	}
}
0