結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2020-10-27 16:00:18 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,097 bytes |
| コンパイル時間 | 71 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 34,816 KB |
| 最終ジャッジ日時 | 2024-07-21 21:56:37 |
| 合計ジャッジ時間 | 10,645 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 31 |
コンパイルメッセージ
Syntax OK
ソースコード
class UnionFind
def initialize(n)
@size = Array.new(n, 1)
@rank = Array.new(n, 0)
@parent = []
(0..n).each do |i|
@parent[i] = i
end
end
def find(x)
if @parent[x] == x
x
else
@parent[x] = find(@parent[x])
end
end
def unite(x, y)
x = find(x)
y = find(y)
return if x == y
if @rank[x] < @rank[y]
@parent[x] = y
@size[y] += @size[x]
else
@parent[y] = x
@size[x] += @size[y]
@rank[x] += 1 if @rank[x] == @rank[y]
end
end
def same?(x, y)
find(x) == find(y)
end
def size(x)
@size[find(x)]
end
end
N, A, B = gets.split.map(&:to_i)
X = gets.split.map(&:to_i)
uf = UnionFind.new(N)
l = 0
r = 1
while l < r
a = X[l]
b = X[r]
d = b - a
if A <= d && d <= B
uf.unite(l, r)
end
if d < A
if r + 1 < N
r += 1
else
l += 1
end
elsif B < d
l += 1
else
if r + 1 < N
if X[r + 1] - a <= B
r += 1
else
l += 1
end
else
l += 1
end
end
end
N.times do |i|
puts uf.size(i)
end
siman