結果
問題 |
No.1170 Never Want to Walk
|
ユーザー |
|
提出日時 | 2025-10-09 09:43:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 203 ms / 2,000 ms |
コード長 | 1,405 bytes |
コンパイル時間 | 4,272 ms |
コンパイル使用メモリ | 82,252 KB |
実行使用メモリ | 109,300 KB |
最終ジャッジ日時 | 2025-10-09 09:44:08 |
合計ジャッジ時間 | 6,677 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 37 |
ソースコード
class stationConectivity(): def __init__(self, num_station): self.parent = [-1]*(num_station) def find(self, id): if self.parent[id]<0: return id else: self.parent[id] = self.find(self.parent[id]) return self.parent[id] def union(self, x_id, y_id): x_root = self.find (x_id) y_root = self.find(y_id) if x_root != y_root: if self.parent[x_root] > self.parent[y_root]: x_root, y_root = y_root, x_root self.parent[x_root] += self.parent[y_root] self.parent[y_root] = x_root def countReachable(self, id): return self.parent[self.find(id)]*-1 def main(): num_station, A, B = map(int, input().split()) xi = list(map(int, input().split())) railway = stationConectivity(num_station) # lはA<=x-x[l]を満たす最初の位置 # rはx-x[r]<Bを満たさなくなった最初の位置 l, r=0, 0 for i, x in enumerate(xi): while l<num_station and xi[l]-x < A: l+=1 while r<num_station and xi[r]-x <= B: r+=1 for j in range(l, r): railway.union(i, j) # ループの最後にlをrの近くまでワープさせる l = max(0, r-2) for i in range(num_station): print(railway.countReachable(i)) if __name__ == "__main__": main()