結果
問題 | No.168 ものさし |
ユーザー | H3PO4 |
提出日時 | 2020-05-10 09:28:43 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,153 ms / 2,000 ms |
コード長 | 1,348 bytes |
コンパイル時間 | 83 ms |
コンパイル使用メモリ | 10,940 KB |
実行使用メモリ | 62,372 KB |
最終ジャッジ日時 | 2023-09-21 10:49:55 |
合計ジャッジ時間 | 9,585 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 231 ms
20,592 KB |
testcase_01 | AC | 16 ms
8,556 KB |
testcase_02 | AC | 16 ms
8,492 KB |
testcase_03 | AC | 16 ms
8,412 KB |
testcase_04 | AC | 15 ms
8,412 KB |
testcase_05 | AC | 15 ms
8,504 KB |
testcase_06 | AC | 15 ms
8,552 KB |
testcase_07 | AC | 15 ms
8,364 KB |
testcase_08 | AC | 15 ms
8,556 KB |
testcase_09 | AC | 21 ms
8,932 KB |
testcase_10 | AC | 36 ms
9,924 KB |
testcase_11 | AC | 205 ms
19,280 KB |
testcase_12 | AC | 723 ms
45,592 KB |
testcase_13 | AC | 1,035 ms
61,448 KB |
testcase_14 | AC | 1,050 ms
62,320 KB |
testcase_15 | AC | 16 ms
8,460 KB |
testcase_16 | AC | 19 ms
8,796 KB |
testcase_17 | AC | 28 ms
9,116 KB |
testcase_18 | AC | 58 ms
11,064 KB |
testcase_19 | AC | 1,117 ms
60,304 KB |
testcase_20 | AC | 1,138 ms
61,772 KB |
testcase_21 | AC | 1,150 ms
62,372 KB |
testcase_22 | AC | 1,153 ms
61,768 KB |
ソースコード
import itertools from math import isqrt 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)] lst = [] 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) lst.append((ceil(dist, 10) * 10, p1, p2)) lst.sort() uf = UnionFind(N) for dist, p1, p2 in lst: uf.unite(p1, p2) if uf.issame(0, N - 1): print(dist) break