結果
問題 | No.1170 Never Want to Walk |
ユーザー | Chihaya_chan |
提出日時 | 2020-09-05 00:13:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 556 ms / 2,000 ms |
コード長 | 1,969 bytes |
コンパイル時間 | 239 ms |
コンパイル使用メモリ | 82,096 KB |
実行使用メモリ | 109,640 KB |
最終ジャッジ日時 | 2024-11-26 21:13:51 |
合計ジャッジ時間 | 10,312 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,120 KB |
testcase_01 | AC | 43 ms
52,224 KB |
testcase_02 | AC | 39 ms
52,608 KB |
testcase_03 | AC | 39 ms
52,736 KB |
testcase_04 | AC | 39 ms
52,864 KB |
testcase_05 | AC | 40 ms
52,864 KB |
testcase_06 | AC | 39 ms
52,608 KB |
testcase_07 | AC | 41 ms
52,864 KB |
testcase_08 | AC | 39 ms
53,120 KB |
testcase_09 | AC | 39 ms
52,864 KB |
testcase_10 | AC | 37 ms
52,608 KB |
testcase_11 | AC | 39 ms
52,480 KB |
testcase_12 | AC | 59 ms
67,712 KB |
testcase_13 | AC | 62 ms
69,504 KB |
testcase_14 | AC | 63 ms
69,120 KB |
testcase_15 | AC | 60 ms
67,200 KB |
testcase_16 | AC | 59 ms
68,224 KB |
testcase_17 | AC | 61 ms
68,864 KB |
testcase_18 | AC | 58 ms
66,560 KB |
testcase_19 | AC | 59 ms
67,712 KB |
testcase_20 | AC | 64 ms
69,888 KB |
testcase_21 | AC | 61 ms
67,212 KB |
testcase_22 | AC | 66 ms
70,888 KB |
testcase_23 | AC | 63 ms
69,504 KB |
testcase_24 | AC | 64 ms
70,016 KB |
testcase_25 | AC | 63 ms
69,888 KB |
testcase_26 | AC | 63 ms
68,992 KB |
testcase_27 | AC | 438 ms
108,212 KB |
testcase_28 | AC | 432 ms
107,016 KB |
testcase_29 | AC | 452 ms
107,836 KB |
testcase_30 | AC | 441 ms
108,492 KB |
testcase_31 | AC | 470 ms
108,436 KB |
testcase_32 | AC | 405 ms
108,124 KB |
testcase_33 | AC | 556 ms
109,640 KB |
testcase_34 | AC | 404 ms
108,136 KB |
testcase_35 | AC | 386 ms
109,288 KB |
testcase_36 | AC | 349 ms
106,164 KB |
testcase_37 | AC | 407 ms
107,480 KB |
testcase_38 | AC | 418 ms
108,336 KB |
ソースコード
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * (n+1) 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.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 + 1) 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()) def main(): import bisect N, A, B = map(int, input().split()) D = list(map(int, input().split())) Uni = UnionFind(N+10) que = [] for i, v in enumerate(D): l = bisect.bisect_right(D, v+A-1) + 1 r = bisect.bisect_right(D, v+B) if l<=r: que.append((l, r)) Uni.union(i+1, l) Uni.union(i+1, r) Left, Right = que[0] for i in range(1, len(que)): a, b = que[i] if Left <= a <= Right: Right = b elif a > Right: for j in range(Left, Right): Uni.union(j, j+1) Left = a Right = b for j in range(Left, Right): Uni.union(j, j+1) for i in range(1, N+1): print(Uni.size(i)) return if __name__ == "__main__": main()