結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
iceEiji2
|
| 提出日時 | 2016-11-22 15:14:39 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 104 ms / 5,000 ms |
| コード長 | 623 bytes |
| コンパイル時間 | 73 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 12,928 KB |
| 最終ジャッジ日時 | 2024-07-01 08:10:36 |
| 合計ジャッジ時間 | 4,391 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
Syntax OK
ソースコード
N = gets.to_i
result = -1
queue = [{pos: 1, time: 1}]
check = Array.new(N+1, false)
check[1] = true
while queue.length > 0 do
current = queue.shift
if current[:pos] == N
result = current[:time]
break
end
move = current[:pos].to_s(2).count("1")
if current[:pos] - move > 0 && !check[current[:pos] - move]
queue << {pos: current[:pos] - move, time: current[:time] + 1}
check[current[:pos] - move] = true
end
if current[:pos] + move <= N && !check[current[:pos] + move]
queue << {pos: current[:pos] + move, time: current[:time] + 1}
check[current[:pos] + move] = true
end
end
p result
iceEiji2