結果
問題 | No.168 ものさし |
ユーザー | H3PO4 |
提出日時 | 2020-05-10 09:12:43 |
言語 | Python3 (3.11.6 + numpy 1.26.0 + scipy 1.11.3) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,456 bytes |
コンパイル時間 | 225 ms |
コンパイル使用メモリ | 11,120 KB |
実行使用メモリ | 48,744 KB |
最終ジャッジ日時 | 2023-09-21 10:28:36 |
合計ジャッジ時間 | 7,748 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 455 ms
48,744 KB |
testcase_01 | AC | 19 ms
8,812 KB |
testcase_02 | AC | 19 ms
8,868 KB |
testcase_03 | AC | 18 ms
8,888 KB |
testcase_04 | AC | 17 ms
8,816 KB |
testcase_05 | AC | 18 ms
8,764 KB |
testcase_06 | AC | 18 ms
8,868 KB |
testcase_07 | AC | 17 ms
8,760 KB |
testcase_08 | AC | 18 ms
8,760 KB |
testcase_09 | AC | 26 ms
9,664 KB |
testcase_10 | AC | 48 ms
11,132 KB |
testcase_11 | AC | 175 ms
18,860 KB |
testcase_12 | AC | 545 ms
37,900 KB |
testcase_13 | AC | 789 ms
48,484 KB |
testcase_14 | AC | 768 ms
48,540 KB |
testcase_15 | AC | 18 ms
8,816 KB |
testcase_16 | AC | 24 ms
9,556 KB |
testcase_17 | AC | 37 ms
10,692 KB |
testcase_18 | AC | 90 ms
16,604 KB |
testcase_19 | TLE | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
ソースコード
import itertools from math import isqrt from collections import defaultdict ceil = lambda a, b: (a + b - 1) // b ceil_sq = lambda n: 1 + isqrt(n - 1) class UnionFind: def __init__(self, n): self.n = n self.parent = [i for i in range(n)] self.height = [1] * n self.size = [1] * n def find(self, x): if self.parent[x] == x: return x else: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.height[x] < self.height[y]: self.parent[x] = y self.size[y] += self.size[x] else: self.parent[y] = x self.size[x] += self.size[y] if self.height[x] == self.height[y]: self.height[x] += 1 def issame(self, x, y): return self.find(x) == self.find(y) N = int(input()) P = [tuple(map(int, input().split())) for _ in range(N)] d = defaultdict(list) for p1, p2 in itertools.combinations(range(N), 2): dist = ceil_sq((P[p1][0] - P[p2][0]) ** 2 + (P[p1][1] - P[p2][1]) ** 2) d[ceil(dist, 10) * 10].append((p1, p2)) lst = sorted(list(d.items())) lst.sort() uf = UnionFind(N) for dist, points in lst: for p1, p2 in points: uf.unite(p1, p2) if uf.issame(0, N - 1): print(dist) break