結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2015-05-31 17:50:22 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 98 ms / 5,000 ms |
コード長 | 576 bytes |
コンパイル時間 | 41 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-07-01 07:22:05 |
合計ジャッジ時間 | 4,121 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
コンパイルメッセージ
Syntax OK
ソースコード
n = gets.to_i memo_array = Array.new(n, -1) memo_array[0] = 1 current_cells = [0] count = 2 while current_cells.length > 0 next_cells = [] current_cells.each do |cell| move_len = (cell + 1).to_s(2).count '1' back, forward = cell - move_len, cell + move_len if back > 0 and memo_array[back] == -1 next_cells.push back memo_array[back] = count end if forward < n and memo_array[forward] == -1 next_cells.push forward memo_array[forward] = count end end count += 1 current_cells = next_cells end puts memo_array[n-1]