結果
問題 |
No.1577 織姫と彦星2
|
ユーザー |
![]() |
提出日時 | 2021-06-29 23:13:32 |
言語 | Crystal (1.14.0) |
結果 |
AC
|
実行時間 | 45 ms / 2,000 ms |
コード長 | 727 bytes |
コンパイル時間 | 11,553 ms |
コンパイル使用メモリ | 296,500 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 01:54:25 |
合計ジャッジ時間 | 13,991 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 53 |
ソースコード
def read x = 0 while (c = STDIN.read_char) && c.ascii_number? x = x &* 10 &+ (c.ord - 48) end x end n = read s = read t = read a = Pointer(Int32).malloc(n &+ 2) n.times do |i| a[i] = read end a[n] = s a[n &+ 1] = t hash = Hash(Int32, Int32).new(n &+ 2) n.times do |i| hash[a[i]] = i end hash[s] = n hash[t] = n &+ 1 que = Pointer(Int32).malloc(n + 2) que[0] = n size = 1 dist = Pointer(Int32).malloc(n + 2) dist[n] = 1 while size != 0 i = que.value que += 1 size &-= 1 d = dist[i] ai = a[i] puts(d &- 2) + exit if i == n &+ 1 bit = 1 30.times do if (j = hash[ai ^ bit]?) && dist[j] == 0 dist[j] = d &+ 1 que[size] = j size &+= 1 end bit <<= 1 end end puts -1