結果
問題 | No.1170 Never Want to Walk |
ユーザー | 👑 rin204 |
提出日時 | 2022-06-30 19:02:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 532 ms / 2,000 ms |
コード長 | 1,766 bytes |
コンパイル時間 | 174 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 103,904 KB |
最終ジャッジ日時 | 2024-11-24 17:43:08 |
合計ジャッジ時間 | 8,356 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,708 KB |
testcase_01 | AC | 35 ms
53,136 KB |
testcase_02 | AC | 40 ms
53,988 KB |
testcase_03 | AC | 36 ms
52,684 KB |
testcase_04 | AC | 36 ms
53,004 KB |
testcase_05 | AC | 35 ms
53,044 KB |
testcase_06 | AC | 36 ms
53,072 KB |
testcase_07 | AC | 36 ms
53,380 KB |
testcase_08 | AC | 37 ms
53,292 KB |
testcase_09 | AC | 39 ms
52,428 KB |
testcase_10 | AC | 40 ms
53,288 KB |
testcase_11 | AC | 37 ms
53,148 KB |
testcase_12 | AC | 62 ms
68,164 KB |
testcase_13 | AC | 60 ms
70,784 KB |
testcase_14 | AC | 61 ms
71,296 KB |
testcase_15 | AC | 58 ms
67,968 KB |
testcase_16 | AC | 58 ms
68,864 KB |
testcase_17 | AC | 60 ms
70,656 KB |
testcase_18 | AC | 57 ms
68,096 KB |
testcase_19 | AC | 57 ms
68,608 KB |
testcase_20 | AC | 62 ms
70,528 KB |
testcase_21 | AC | 62 ms
68,352 KB |
testcase_22 | AC | 66 ms
70,912 KB |
testcase_23 | AC | 63 ms
71,424 KB |
testcase_24 | AC | 57 ms
69,120 KB |
testcase_25 | AC | 58 ms
70,528 KB |
testcase_26 | AC | 59 ms
71,040 KB |
testcase_27 | AC | 397 ms
103,196 KB |
testcase_28 | AC | 410 ms
103,508 KB |
testcase_29 | AC | 444 ms
103,904 KB |
testcase_30 | AC | 425 ms
103,524 KB |
testcase_31 | AC | 411 ms
103,136 KB |
testcase_32 | AC | 355 ms
102,872 KB |
testcase_33 | AC | 532 ms
103,332 KB |
testcase_34 | AC | 358 ms
103,528 KB |
testcase_35 | AC | 333 ms
103,408 KB |
testcase_36 | AC | 333 ms
103,052 KB |
testcase_37 | AC | 355 ms
102,992 KB |
testcase_38 | AC | 388 ms
103,848 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))