結果

問題 No.2355 Unhappy Back Dance
ユーザー ks2mks2m
提出日時 2023-06-16 22:45:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,605 bytes
コンパイル時間 4,410 ms
コンパイル使用メモリ 86,172 KB
実行使用メモリ 73,432 KB
最終ジャッジ日時 2023-09-06 21:19:30
合計ジャッジ時間 46,130 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
56,888 KB
testcase_01 AC 129 ms
56,848 KB
testcase_02 AC 135 ms
56,460 KB
testcase_03 AC 110 ms
55,416 KB
testcase_04 AC 133 ms
56,464 KB
testcase_05 AC 136 ms
56,780 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 111 ms
55,816 KB
testcase_16 AC 2,351 ms
67,168 KB
testcase_17 AC 2,406 ms
66,116 KB
testcase_18 AC 2,256 ms
65,436 KB
testcase_19 AC 2,264 ms
66,080 KB
testcase_20 AC 2,408 ms
65,984 KB
testcase_21 AC 1,324 ms
64,492 KB
testcase_22 AC 586 ms
64,152 KB
testcase_23 AC 622 ms
65,004 KB
testcase_24 AC 2,134 ms
65,556 KB
testcase_25 AC 1,422 ms
65,904 KB
testcase_26 AC 1,367 ms
65,748 KB
testcase_27 AC 1,245 ms
67,228 KB
testcase_28 AC 248 ms
59,120 KB
testcase_29 AC 325 ms
59,172 KB
testcase_30 AC 1,977 ms
65,772 KB
testcase_31 AC 1,584 ms
65,004 KB
testcase_32 AC 522 ms
63,636 KB
testcase_33 AC 1,140 ms
65,552 KB
testcase_34 AC 219 ms
59,400 KB
testcase_35 AC 261 ms
60,172 KB
testcase_36 AC 1,420 ms
66,156 KB
testcase_37 AC 869 ms
65,460 KB
testcase_38 AC 998 ms
65,400 KB
testcase_39 AC 900 ms
65,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
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);
				}
			}
			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;
				long min = Long.MAX_VALUE;
				long minidx = 0;
				long max = -1;
				long maxidx = 0;
				for (int j : list) {
					if (z[j] < min) {
						min = z[j];
						minidx = j;
					}
					if (z[j] > max) {
						max = z[j];
						maxidx = j;
					}
				}
				if (minidx == i || maxidx == i) {
					ans++;
					break;
				}
			}
		}
		System.out.println(ans);
	}

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