結果

問題 No.1577 織姫と彦星2
ユーザー yuruhiya
提出日時 2021-07-03 09:14:05
言語 Crystal
(1.14.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 396 bytes
コンパイル時間 12,823 ms
コンパイル使用メモリ 296,428 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-06-30 01:55:43
合計ジャッジ時間 16,264 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

n = read_line.to_i
s, t = read_line.split.map(&.to_i)
a = read_line.split.map(&.to_i) + [s, t]
hash = a.zip(0..).to_h
que = Deque{n}
dist = [nil.as(Int32?)] * (n + 2)
dist[n] = -1
while i = que.shift?
  d = dist[i].not_nil!
  puts(d) + exit if i == n + 1
  (0..30).each do |bit|
    if (j = hash[a[i] ^ (1 << bit)]?) && dist[j].nil?
      dist[j] = d + 1
      que << j
    end
  end
end
puts -1
0