結果
問題 | No.1577 織姫と彦星2 |
ユーザー |
![]() |
提出日時 | 2021-06-30 17:05:04 |
言語 | Crystal (1.14.0) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 1,209 bytes |
コンパイル時間 | 12,628 ms |
コンパイル使用メモリ | 294,680 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-27 03:18:05 |
合計ジャッジ時間 | 15,202 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 53 |
コンパイルメッセージ
In Main.cr:28:12 28 | STDOUT.write_utf8 Slice.new(now, ptr + 5 - now) ^--------- Warning: Deprecated IO::FileDescriptor#write_utf8. Use `#write_string` instead. A total of 1 warnings were found.
ソースコード
lib LibC fun getchar_unlocked : Char fun putchar_unlocked(Char) end def read x = 0 loop do c = LibC.getchar_unlocked break unless 48 <= c x &*= 10 x &+= c &- 48 end x end def putui(x : Int32) if x == 0 LibC.putchar_unlocked(48) else ptr = Pointer(UInt8).malloc(5) now = ptr + 5 while x != 0 now -= 1 now.value = (48 &+ x % 10).to_u8! x //= 10 end STDOUT.write_utf8 Slice.new(now, ptr + 5 - now) end 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] if i == n &+ 1 putui(d &- 2) LibC.putchar_unlocked(10) exit end 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 LibC.putchar_unlocked 45 LibC.putchar_unlocked 49 LibC.putchar_unlocked 10