結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-31 17:14:45 |
| 言語 | Ruby (3.4.1) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 536 bytes |
| コンパイル時間 | 176 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 733,952 KB |
| 最終ジャッジ日時 | 2024-11-22 11:04:44 |
| 合計ジャッジ時間 | 180,156 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 MLE * 30 |
コンパイルメッセージ
Main.rb:29: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
n = gets.to_i
arr = (1..n).to_a.map { |i| i.digits(2).count(1) }
INF = 10000000
dp = [INF] * n
dp[0] = 1
# p arr
que = []
# queueの中身は[現在のマス, 移動数]
que.unshift([0, 1])
while !que.empty?
index, move_count = que.pop()
if index == n-1
puts move_count
exit 0
end
if index + arr[index] <= n - 1
que.unshift([index + arr[index], move_count + 1])
end
if index - arr[index] >= 0
que.unshift([index - arr[index], move_count + 1])
end
end
puts -1