結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-07 20:22:02 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,213 bytes |
| コンパイル時間 | 386 ms |
| コンパイル使用メモリ | 82,632 KB |
| 実行使用メモリ | 318,612 KB |
| 最終ジャッジ日時 | 2025-10-07 20:22:09 |
| 合計ジャッジ時間 | 6,646 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 |
| other | WA * 25 TLE * 1 -- * 11 |
ソースコード
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, xi, A, B):
for i, x in enumerate(xi):
for j, upTox in enumerate(xi[:i]):
if upTox >= B:
break
if A <= x-upTox <= B:
x_root = self.find(i)
upTox_root = self.find(j)
if x_root != upTox_root:
if self.parent[x_root] > self.parent[upTox_root]:
x_root, upTox_root = upTox_root, x_root
self.parent[upTox_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)
railway.union(xi, A, B)
for i in range(num_station):
print(railway.countReachable(i))
if __name__ == "__main__":
main()