結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-08-27 20:41:44 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 502 bytes |
コンパイル時間 | 64 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,544 KB |
最終ジャッジ日時 | 2024-11-08 19:59:02 |
合計ジャッジ時間 | 10,141 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 WA * 1 |
コンパイルメッセージ
Main.rb:26: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
def p_bit(position) position.to_s(2).split('').map(&:to_i).inject(:+) end n = gets.to_i reached = [1] deep = 0 rd = [[1]] loop do array = [] rd[deep].each do |position| b = p_bit(position) [position + b, position - b].each do |a| next if a < 0 || a > n unless reached.include?(a) array << a reached << a end end end deep += 1 if array.include?(n) puts deep + 1 break end if array.empty? puts -1 break end rd << array end