結果
問題 | No.1170 Never Want to Walk |
ユーザー | rei60 |
提出日時 | 2020-08-22 15:52:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 712 ms / 2,000 ms |
コード長 | 2,488 bytes |
コンパイル時間 | 208 ms |
コンパイル使用メモリ | 81,780 KB |
実行使用メモリ | 106,252 KB |
最終ジャッジ日時 | 2024-10-15 10:01:30 |
合計ジャッジ時間 | 11,137 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,736 KB |
testcase_01 | AC | 39 ms
52,352 KB |
testcase_02 | AC | 43 ms
52,736 KB |
testcase_03 | AC | 39 ms
52,352 KB |
testcase_04 | AC | 40 ms
52,480 KB |
testcase_05 | AC | 38 ms
52,352 KB |
testcase_06 | AC | 40 ms
52,864 KB |
testcase_07 | AC | 40 ms
52,992 KB |
testcase_08 | AC | 39 ms
52,864 KB |
testcase_09 | AC | 39 ms
52,864 KB |
testcase_10 | AC | 39 ms
52,864 KB |
testcase_11 | AC | 40 ms
52,480 KB |
testcase_12 | AC | 69 ms
71,808 KB |
testcase_13 | AC | 78 ms
75,264 KB |
testcase_14 | AC | 78 ms
75,264 KB |
testcase_15 | AC | 66 ms
71,040 KB |
testcase_16 | AC | 69 ms
72,320 KB |
testcase_17 | AC | 80 ms
75,472 KB |
testcase_18 | AC | 67 ms
70,656 KB |
testcase_19 | AC | 69 ms
72,576 KB |
testcase_20 | AC | 79 ms
75,520 KB |
testcase_21 | AC | 67 ms
71,552 KB |
testcase_22 | AC | 79 ms
75,656 KB |
testcase_23 | AC | 78 ms
75,392 KB |
testcase_24 | AC | 77 ms
75,764 KB |
testcase_25 | AC | 80 ms
75,284 KB |
testcase_26 | AC | 78 ms
75,392 KB |
testcase_27 | AC | 605 ms
104,932 KB |
testcase_28 | AC | 541 ms
104,380 KB |
testcase_29 | AC | 712 ms
106,252 KB |
testcase_30 | AC | 577 ms
105,056 KB |
testcase_31 | AC | 602 ms
104,944 KB |
testcase_32 | AC | 406 ms
104,668 KB |
testcase_33 | AC | 445 ms
104,240 KB |
testcase_34 | AC | 438 ms
105,200 KB |
testcase_35 | AC | 455 ms
104,980 KB |
testcase_36 | AC | 444 ms
104,300 KB |
testcase_37 | AC | 418 ms
104,364 KB |
testcase_38 | AC | 385 ms
105,128 KB |
ソースコード
from bisect import bisect_left, bisect_right class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n self.left = [0] * n self.right = [0] * n for i in range(n): self.left[i] = i self.right[i] = i 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 if self.parents[x] > self.parents[y]: x, y = y, x self.left[x] = min(self.left[x], self.left[y]) self.right[x] = max(self.right[x], self.right[y]) self.parents[x] += self.parents[y] self.parents[y] = x def findleft(self, x): x = self.find(x) return self.left[x] def findright(self, x): x = self.find(x) return self.right[x] def pair(self, x): x = self.find(x) return (self.left[x], self.right[x]) def union_range(self, a, b): if a >= b: return else: while self.findright(a) < b: self.union(self.findright(a), self.findright(a) + 1) 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 len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} 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())) uf = UnionFind(N) for idx, i in enumerate(X): L_left = bisect_left(X, i-B) L_right = bisect_right(X, i-A) R_left = bisect_left(X, i+A) R_right = bisect_right(X, i+B) #print(L_left, L_right, R_left, R_right) if L_right - L_left > 0: uf.union(idx, L_left) uf.union_range(L_left, L_right-1) if R_right - R_left > 0: uf.union(idx, R_left) uf.union_range(R_left, R_right-1) for i in range(N): print(uf.size(i))