結果
問題 | No.1170 Never Want to Walk |
ユーザー | 👑 rin204 |
提出日時 | 2022-06-30 19:02:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 639 ms / 2,000 ms |
コード長 | 1,766 bytes |
コンパイル時間 | 354 ms |
コンパイル使用メモリ | 86,936 KB |
実行使用メモリ | 106,636 KB |
最終ジャッジ日時 | 2023-08-16 06:35:26 |
合計ジャッジ時間 | 11,553 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 80 ms
71,340 KB |
testcase_01 | AC | 79 ms
71,404 KB |
testcase_02 | AC | 78 ms
71,336 KB |
testcase_03 | AC | 79 ms
71,340 KB |
testcase_04 | AC | 79 ms
71,416 KB |
testcase_05 | AC | 78 ms
71,376 KB |
testcase_06 | AC | 78 ms
71,248 KB |
testcase_07 | AC | 79 ms
71,476 KB |
testcase_08 | AC | 79 ms
71,456 KB |
testcase_09 | AC | 78 ms
71,356 KB |
testcase_10 | AC | 80 ms
71,528 KB |
testcase_11 | AC | 79 ms
71,368 KB |
testcase_12 | AC | 101 ms
76,276 KB |
testcase_13 | AC | 105 ms
76,124 KB |
testcase_14 | AC | 106 ms
76,160 KB |
testcase_15 | AC | 101 ms
76,228 KB |
testcase_16 | AC | 101 ms
76,032 KB |
testcase_17 | AC | 105 ms
76,432 KB |
testcase_18 | AC | 100 ms
76,144 KB |
testcase_19 | AC | 100 ms
76,140 KB |
testcase_20 | AC | 104 ms
76,324 KB |
testcase_21 | AC | 101 ms
76,156 KB |
testcase_22 | AC | 105 ms
76,396 KB |
testcase_23 | AC | 110 ms
76,744 KB |
testcase_24 | AC | 104 ms
76,256 KB |
testcase_25 | AC | 105 ms
75,860 KB |
testcase_26 | AC | 109 ms
75,768 KB |
testcase_27 | AC | 514 ms
104,076 KB |
testcase_28 | AC | 517 ms
104,264 KB |
testcase_29 | AC | 544 ms
104,848 KB |
testcase_30 | AC | 522 ms
104,752 KB |
testcase_31 | AC | 518 ms
104,504 KB |
testcase_32 | AC | 443 ms
104,216 KB |
testcase_33 | AC | 639 ms
104,416 KB |
testcase_34 | AC | 450 ms
104,448 KB |
testcase_35 | AC | 429 ms
104,728 KB |
testcase_36 | AC | 410 ms
104,108 KB |
testcase_37 | AC | 438 ms
104,132 KB |
testcase_38 | AC | 476 ms
106,636 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))