結果

問題 No.1170 Never Want to Walk
ユーザー Craft Boss
提出日時 2025-10-08 20:19:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,311 bytes
コンパイル時間 4,629 ms
コンパイル使用メモリ 82,652 KB
実行使用メモリ 109,100 KB
最終ジャッジ日時 2025-10-08 20:20:15
合計ジャッジ時間 8,571 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

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)

    for i in range(num_station):
        print(railway.countReachable(i))

if __name__ == "__main__":
    main()
0