結果
問題 | No.1170 Never Want to Walk |
ユーザー | H3PO4 |
提出日時 | 2022-05-02 21:06:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 254 ms / 2,000 ms |
コード長 | 1,639 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 86,848 KB |
実行使用メモリ | 110,648 KB |
最終ジャッジ日時 | 2023-09-14 18:11:46 |
合計ジャッジ時間 | 7,967 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
71,172 KB |
testcase_01 | AC | 72 ms
71,176 KB |
testcase_02 | AC | 74 ms
71,028 KB |
testcase_03 | AC | 71 ms
71,088 KB |
testcase_04 | AC | 71 ms
71,060 KB |
testcase_05 | AC | 72 ms
71,084 KB |
testcase_06 | AC | 72 ms
71,176 KB |
testcase_07 | AC | 73 ms
70,904 KB |
testcase_08 | AC | 72 ms
71,316 KB |
testcase_09 | AC | 71 ms
71,052 KB |
testcase_10 | AC | 74 ms
71,056 KB |
testcase_11 | AC | 73 ms
71,088 KB |
testcase_12 | AC | 87 ms
75,512 KB |
testcase_13 | AC | 103 ms
76,440 KB |
testcase_14 | AC | 88 ms
76,008 KB |
testcase_15 | AC | 86 ms
75,404 KB |
testcase_16 | AC | 85 ms
75,444 KB |
testcase_17 | AC | 94 ms
75,816 KB |
testcase_18 | AC | 82 ms
75,748 KB |
testcase_19 | AC | 90 ms
75,560 KB |
testcase_20 | AC | 97 ms
76,164 KB |
testcase_21 | AC | 89 ms
75,556 KB |
testcase_22 | AC | 100 ms
76,084 KB |
testcase_23 | AC | 96 ms
75,956 KB |
testcase_24 | AC | 99 ms
76,152 KB |
testcase_25 | AC | 97 ms
76,036 KB |
testcase_26 | AC | 94 ms
76,188 KB |
testcase_27 | AC | 254 ms
110,408 KB |
testcase_28 | AC | 228 ms
110,140 KB |
testcase_29 | AC | 251 ms
110,648 KB |
testcase_30 | AC | 240 ms
109,904 KB |
testcase_31 | AC | 253 ms
110,044 KB |
testcase_32 | AC | 210 ms
109,704 KB |
testcase_33 | AC | 197 ms
110,204 KB |
testcase_34 | AC | 204 ms
110,364 KB |
testcase_35 | AC | 216 ms
110,388 KB |
testcase_36 | AC | 201 ms
110,260 KB |
testcase_37 | AC | 201 ms
110,368 KB |
testcase_38 | AC | 210 ms
110,580 KB |
ソースコード
class UnionFind: __slots__ = ["n", "parent", "height", "size"] def __init__(self, n): self.n = n self.parent = [i for i in range(n)] self.height = [1] * n self.size = [1] * n def find(self, x): if self.parent[x] == x: return x else: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.height[x] < self.height[y]: self.parent[x] = y self.size[y] += self.size[x] else: self.parent[y] = x self.size[x] += self.size[y] if self.height[x] == self.height[y]: self.height[x] += 1 def issame(self, x, y): return self.find(x) == self.find(y) def group_size(self, x): return self.size[self.find(x)] def group_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.parent) if i == x] def group_count(self): return len(self.roots()) N, A, B = map(int, input().split()) X = tuple(map(int, input().split())) l = 0 # 閉区間 r = 0 # 開区間 old_r = 0 uf = UnionFind(N) for i, xi in enumerate(X): while l < N and X[l] - xi < A: l += 1 if l == N: break r = max(l, old_r - 1) while r < N and X[r] - xi <= B: uf.unite(i, r) r += 1 old_r = r for i in range(N): print(uf.group_size(i))