結果
問題 | No.1170 Never Want to Walk |
ユーザー | rei60 |
提出日時 | 2020-08-29 13:01:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 805 ms / 2,000 ms |
コード長 | 2,640 bytes |
コンパイル時間 | 186 ms |
コンパイル使用メモリ | 82,296 KB |
実行使用メモリ | 105,588 KB |
最終ジャッジ日時 | 2024-11-14 05:36:56 |
合計ジャッジ時間 | 12,866 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,476 KB |
testcase_01 | AC | 37 ms
52,952 KB |
testcase_02 | AC | 41 ms
54,416 KB |
testcase_03 | AC | 39 ms
53,548 KB |
testcase_04 | AC | 40 ms
53,720 KB |
testcase_05 | AC | 37 ms
53,744 KB |
testcase_06 | AC | 38 ms
53,792 KB |
testcase_07 | AC | 38 ms
53,692 KB |
testcase_08 | AC | 38 ms
53,816 KB |
testcase_09 | AC | 38 ms
53,512 KB |
testcase_10 | AC | 38 ms
54,136 KB |
testcase_11 | AC | 37 ms
53,272 KB |
testcase_12 | AC | 66 ms
72,648 KB |
testcase_13 | AC | 79 ms
76,000 KB |
testcase_14 | AC | 78 ms
75,728 KB |
testcase_15 | AC | 65 ms
72,264 KB |
testcase_16 | AC | 68 ms
73,552 KB |
testcase_17 | AC | 78 ms
75,976 KB |
testcase_18 | AC | 65 ms
71,836 KB |
testcase_19 | AC | 69 ms
73,612 KB |
testcase_20 | AC | 78 ms
75,736 KB |
testcase_21 | AC | 67 ms
72,576 KB |
testcase_22 | AC | 80 ms
76,060 KB |
testcase_23 | AC | 79 ms
75,988 KB |
testcase_24 | AC | 78 ms
76,032 KB |
testcase_25 | AC | 82 ms
75,876 KB |
testcase_26 | AC | 80 ms
75,844 KB |
testcase_27 | AC | 783 ms
104,320 KB |
testcase_28 | AC | 766 ms
104,492 KB |
testcase_29 | AC | 706 ms
104,900 KB |
testcase_30 | AC | 680 ms
104,980 KB |
testcase_31 | AC | 805 ms
104,260 KB |
testcase_32 | AC | 532 ms
104,640 KB |
testcase_33 | AC | 670 ms
104,280 KB |
testcase_34 | AC | 612 ms
104,752 KB |
testcase_35 | AC | 629 ms
105,588 KB |
testcase_36 | AC | 670 ms
104,716 KB |
testcase_37 | AC | 598 ms
104,200 KB |
testcase_38 | AC | 605 ms
105,448 KB |
ソースコード
# -*- coding: utf-8 -*- """ Created on Sat Aug 22 11:41:03 2020 """ 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: stack = [] prt = self.parents while prt[x] >= 0: stack.append(x) x = prt[x] for y in stack: prt[y] = x return 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) 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))