結果
問題 | No.1170 Never Want to Walk |
ユーザー | 👑 rin204 |
提出日時 | 2022-06-30 19:02:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 600 ms / 2,000 ms |
コード長 | 1,766 bytes |
コンパイル時間 | 193 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 103,832 KB |
最終ジャッジ日時 | 2024-05-03 15:40:50 |
合計ジャッジ時間 | 9,718 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,480 KB |
testcase_01 | AC | 40 ms
52,608 KB |
testcase_02 | AC | 40 ms
52,608 KB |
testcase_03 | AC | 42 ms
52,472 KB |
testcase_04 | AC | 40 ms
52,736 KB |
testcase_05 | AC | 40 ms
52,992 KB |
testcase_06 | AC | 40 ms
52,224 KB |
testcase_07 | AC | 40 ms
52,620 KB |
testcase_08 | AC | 41 ms
52,480 KB |
testcase_09 | AC | 41 ms
52,480 KB |
testcase_10 | AC | 40 ms
52,224 KB |
testcase_11 | AC | 41 ms
52,224 KB |
testcase_12 | AC | 64 ms
68,352 KB |
testcase_13 | AC | 68 ms
71,040 KB |
testcase_14 | AC | 70 ms
71,168 KB |
testcase_15 | AC | 63 ms
68,608 KB |
testcase_16 | AC | 64 ms
69,120 KB |
testcase_17 | AC | 68 ms
71,040 KB |
testcase_18 | AC | 63 ms
67,712 KB |
testcase_19 | AC | 63 ms
68,736 KB |
testcase_20 | AC | 66 ms
70,144 KB |
testcase_21 | AC | 64 ms
67,584 KB |
testcase_22 | AC | 68 ms
70,784 KB |
testcase_23 | AC | 68 ms
71,808 KB |
testcase_24 | AC | 64 ms
70,016 KB |
testcase_25 | AC | 66 ms
70,528 KB |
testcase_26 | AC | 67 ms
71,040 KB |
testcase_27 | AC | 463 ms
103,032 KB |
testcase_28 | AC | 465 ms
103,336 KB |
testcase_29 | AC | 498 ms
103,772 KB |
testcase_30 | AC | 468 ms
103,472 KB |
testcase_31 | AC | 469 ms
102,948 KB |
testcase_32 | AC | 426 ms
102,992 KB |
testcase_33 | AC | 600 ms
103,016 KB |
testcase_34 | AC | 412 ms
103,832 KB |
testcase_35 | AC | 372 ms
103,412 KB |
testcase_36 | AC | 384 ms
103,364 KB |
testcase_37 | AC | 392 ms
103,376 KB |
testcase_38 | AC | 435 ms
103,592 KB |
ソースコード
from bisect import bisect_left, bisect_right class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n self.group = n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return self.group -= 1 if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return self.group def all_group_members(self): dic = {r:[] for r in self.roots()} for i in range(self.n): dic[self.find(i)].append(i) return dic def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) n, a, b = map(int, input().split()) X = list(map(int, input().split())) imos = [0] * (n + 1) UF = UnionFind(n) for i, x in enumerate(X): ll = bisect_left(X, x + a) rr = bisect_right(X, x + b) if ll != rr: UF.union(i, ll) UF.union(i, rr - 1) imos[ll] += 1 imos[rr - 1] -= 1 tot = 0 for i in range(n): imos[i] += imos[i - 1] if imos[i] > 0: UF.union(i, i + 1) for i in range(n): print(UF.size(i))