結果

問題 No.1577 織姫と彦星2
ユーザー yuruhiya
提出日時 2021-06-29 20:55:28
言語 Crystal
(1.19.1)
コンパイル:
crystal build -Donline_judge -o a.out --release --no-debug _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 545 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 13,228 ms
コンパイル使用メモリ 339,976 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2026-03-12 10:46:02
合計ジャッジ時間 13,198 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21 WA * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n = read_line.to_i
s, t = read_line.split.map(&.to_i)
a = read_line.split.map(&.to_i)
stones = a + [s, t]
hash = stones.zip(0..).to_h
g = (1..n + 2).map { [] of Int32 }
stones.each_with_index do |x, i|
  (0..30).each do |bit|
    if j = hash[x ^ (1 << bit)]?
      g[i] << j; g[j] << i
    end
  end
end

que = Deque{hash[s]}
dist = [nil.as(Int32?)] * (n + 2)
dist[hash[s]] = 0
while v = que.pop?
	d = dist[v].not_nil!
	puts(d - 1) + exit if v == hash[t]
	g[v].each do |u|
		if dist[u].nil?
			dist[u] = d + 1
			que << u
		end
	end
end
puts -1
0