結果
問題 | No.1170 Never Want to Walk |
ユーザー | i_taku |
提出日時 | 2024-05-17 15:58:31 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,008 bytes |
コンパイル時間 | 180 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 450,368 KB |
最終ジャッジ日時 | 2024-12-20 11:46:11 |
合計ジャッジ時間 | 31,018 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
57,600 KB |
testcase_01 | AC | 41 ms
246,472 KB |
testcase_02 | AC | 40 ms
59,296 KB |
testcase_03 | AC | 40 ms
246,260 KB |
testcase_04 | AC | 42 ms
57,856 KB |
testcase_05 | AC | 41 ms
246,564 KB |
testcase_06 | AC | 40 ms
57,728 KB |
testcase_07 | AC | 41 ms
246,556 KB |
testcase_08 | AC | 40 ms
57,984 KB |
testcase_09 | AC | 42 ms
249,948 KB |
testcase_10 | AC | 41 ms
57,856 KB |
testcase_11 | AC | 41 ms
277,584 KB |
testcase_12 | AC | 74 ms
75,008 KB |
testcase_13 | AC | 75 ms
297,596 KB |
testcase_14 | AC | 75 ms
75,904 KB |
testcase_15 | AC | 76 ms
70,272 KB |
testcase_16 | AC | 82 ms
71,296 KB |
testcase_17 | AC | 78 ms
70,912 KB |
testcase_18 | AC | 74 ms
69,120 KB |
testcase_19 | AC | 76 ms
69,888 KB |
testcase_20 | AC | 74 ms
68,992 KB |
testcase_21 | AC | 77 ms
69,888 KB |
testcase_22 | AC | 59 ms
64,768 KB |
testcase_23 | AC | 62 ms
66,816 KB |
testcase_24 | AC | 61 ms
64,384 KB |
testcase_25 | AC | 65 ms
64,384 KB |
testcase_26 | AC | 70 ms
68,096 KB |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | AC | 1,292 ms
221,020 KB |
testcase_34 | TLE | - |
testcase_35 | AC | 361 ms
226,908 KB |
testcase_36 | TLE | - |
testcase_37 | AC | 355 ms
225,132 KB |
testcase_38 | AC | 350 ms
450,368 KB |
ソースコード
class UnionFind: def __init__(self, n): self._n = n self._parent = [-1] * n self._roots = set(range(n)) def _find(self, x): if self._parent[x] < 0: return x self._parent[x] = self._find(self._parent[x]) return self._parent[x] def union(self, x, y): x, y = self._find(x), self._find(y) if x == y: return if self._parent[y] < self._parent[x]: x, y = y, x self._parent[x] += self._parent[y] self._parent[y] = x self._roots.discard(y) def same(self, x, y): return self._find(x) == self._find(y) def size(self, x): return -self._parent[self._find(x)] def members(self, x): root = self._find(x) return [i for i in range(self._n) if self._find(i) == root] def all_group_members(self): group_members = dict() for member in range(self._n): root = self._find(member) if root not in group_members: group_members[root] = [] group_members[root].append(member) return group_members def root(self, x): return self._find(x) def roots(self): return self._roots def group_count(self): return len(self.roots()) def group_numbers(self): return [self._find(i) for i in range(self._n)] def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) N, A, B = map(int, input().split()) X = list(map(int, input().split())) idx = {x: i for i, x in enumerate(X)} S = set(X) uf = UnionFind(N) rm = [] while S: sx = S.pop() stack = [sx] while stack: x = stack.pop() for nx in S: if A <= abs(x - nx) <= B: uf.union(idx[x], idx[nx]) rm.append(nx) stack.append(nx) while rm: S.discard(rm.pop()) for i in range(N): print(uf.size(i))