結果
問題 | No.168 ものさし |
ユーザー | butaman |
提出日時 | 2020-10-02 11:09:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,033 ms / 2,000 ms |
コード長 | 1,394 bytes |
コンパイル時間 | 1,501 ms |
コンパイル使用メモリ | 86,992 KB |
実行使用メモリ | 154,956 KB |
最終ジャッジ日時 | 2023-09-22 12:18:21 |
合計ジャッジ時間 | 11,233 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 241 ms
91,596 KB |
testcase_01 | AC | 74 ms
71,668 KB |
testcase_02 | AC | 74 ms
71,828 KB |
testcase_03 | AC | 71 ms
71,888 KB |
testcase_04 | AC | 71 ms
71,696 KB |
testcase_05 | AC | 71 ms
71,532 KB |
testcase_06 | AC | 73 ms
71,696 KB |
testcase_07 | AC | 72 ms
71,576 KB |
testcase_08 | AC | 70 ms
71,896 KB |
testcase_09 | AC | 80 ms
76,376 KB |
testcase_10 | AC | 91 ms
76,768 KB |
testcase_11 | AC | 219 ms
90,592 KB |
testcase_12 | AC | 659 ms
128,488 KB |
testcase_13 | AC | 1,017 ms
154,432 KB |
testcase_14 | AC | 1,033 ms
154,412 KB |
testcase_15 | AC | 72 ms
71,768 KB |
testcase_16 | AC | 80 ms
76,576 KB |
testcase_17 | AC | 85 ms
76,748 KB |
testcase_18 | AC | 102 ms
77,368 KB |
testcase_19 | AC | 974 ms
154,956 KB |
testcase_20 | AC | 1,016 ms
154,400 KB |
testcase_21 | AC | 1,009 ms
154,648 KB |
testcase_22 | AC | 1,026 ms
154,384 KB |
ソースコード
class UnionFind: def __init__(self): self.N = 0 self.parent = [] self.rank = [] def __init__(self, NN): self.N = NN + 1 self.parent = [i for i in range(self.N)] self.rank = [0]*self.N def root(self, aa): if self.parent[aa] == aa: return aa self.parent[aa] = self.root(self.parent[aa]) return self.parent[aa] def sameroot(self, aa, bb): return self.root(aa) == self.root(bb) def unite(self, aa, bb): aa = self.root(aa) bb = self.root(bb) if aa == bb: #no need to unite anymore return if self.rank[aa] < self.rank[bb]: aa, bb = bb, aa if self.rank[aa] == self.rank[bb]: self.rank[aa] += 1 self.parent[bb] = aa N = int(input()) point = [] dist = [] for i in range(N): x, y = map(int, input().split()) point.append((x, y)) for k in range(i): xk, yk = point[k] dd = (xk-x)*(xk-x) + (yk-y)*(yk-y) dist.append((dd, i, k)) #sorted from short to long sortedD = sorted(dist, key=lambda tup: tup[0]) cnt = 0 tree = UnionFind(N) for (d, i, k) in sortedD: tree.unite(i, k) #connected? and be the shortest path if tree.sameroot(0, N-1): dd = int(d**0.5) while dd*dd < d: dd += 1 print(((dd + 9)//10)*10) exit(0)