結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-09-04 09:55:01 |
| 言語 | Crystal (1.14.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 520 bytes |
| コンパイル時間 | 12,917 ms |
| コンパイル使用メモリ | 309,540 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-09-04 09:55:16 |
| 合計ジャッジ時間 | 13,577 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
n = gets.not_nil!.chomp.to_i
ans = Array.new(n + 1, 0)
visited = Array.new(n + 1, false)
que = Deque(Int32).new
que.push(1)
ans[1] = 1
visited[1] = true
while !que.empty?
q = que.shift
cnt = 0
rest = q
while rest > 0
cnt += rest % 2
rest //= 2
end
[-1, 1].each do |i|
next_val = q + i * cnt
if next_val >= 1 && next_val <= n && !visited[next_val]
visited[next_val] = true
ans[next_val] = ans[q] + 1
que.push(next_val)
end
end
end
puts visited[n] ? ans[n] : -1
vjudge1