結果

問題 No.1576 織姫と彦星
ユーザー yuruhiya
提出日時 2021-07-03 09:17:57
言語 Crystal
(1.14.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 356 bytes
コンパイル時間 10,946 ms
コンパイル使用メモリ 296,776 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-30 01:57:11
合計ジャッジ時間 12,623 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

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