結果
問題 | No.1170 Never Want to Walk |
ユーザー |
👑 ![]() |
提出日時 | 2021-02-28 02:06:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 306 ms / 2,000 ms |
コード長 | 1,092 bytes |
コンパイル時間 | 268 ms |
コンパイル使用メモリ | 82,116 KB |
実行使用メモリ | 107,648 KB |
最終ジャッジ日時 | 2024-10-02 18:06:35 |
合計ジャッジ時間 | 8,022 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 37 |
ソースコード
class DisjointSet: def __init__(self, size): self.parent = list(range(size)) self.rank = [0]*size def find(self, x): stack = [] parent = self.parent while parent[x] != x: stack.append(x) x = parent[x] for y in stack: parent[y] = x return x def union(self, x, y): xr, yr = self.find(x), self.find(y) if self.rank[xr] > self.rank[yr]: self.parent[yr] = xr elif self.rank[xr] < self.rank[yr]: self.parent[xr] = yr elif xr != yr: self.parent[yr] = xr self.rank[xr] += 1 n,a,b = map(int,input().split()) X = list(map(int,input().split())) ds = DisjointSet(n) j = 0 for i,xi in enumerate(X): while j < n and X[j] < a+xi: j += 1 if j == n: break if X[j] <= b+xi: ds.union(i,j) while j+1 < n and X[j+1] <= b+xi: ds.union(j,j+1) j += 1 cnt = [0]*n for i in range(n): cnt[ds.find(i)] += 1 for i in range(n): print(cnt[ds.find(i)])