結果

問題 No.1576 織姫と彦星
ユーザー yuruhiyayuruhiya
提出日時 2021-06-29 20:59:56
言語 Crystal
(1.14.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 431 bytes
コンパイル時間 13,866 ms
コンパイル使用メモリ 295,184 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-25 23:25:44
合計ジャッジ時間 13,155 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

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
que = Deque{hash[s]}
dist = [nil.as(Int32?)] * (n + 2)
dist[hash[s]] = -1
while i = que.shift?
  d = dist[i].not_nil!
  puts(d) + exit if i == hash[t]
  (0..30).each do |bit|
    if (j = hash[stones[i] ^ (1 << bit)]?) && dist[j].nil?
      dist[j] = d + 1
      que << j
    end
  end
end
puts -1
0