結果

問題 No.3 ビットすごろく
ユーザー shinjiwebshinjiweb
提出日時 2016-08-27 20:41:44
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 502 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-04-26 07:00:29
合計ジャッジ時間 11,082 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
12,160 KB
testcase_01 AC 100 ms
12,288 KB
testcase_02 AC 104 ms
12,416 KB
testcase_03 AC 152 ms
12,672 KB
testcase_04 AC 113 ms
12,160 KB
testcase_05 AC 260 ms
12,672 KB
testcase_06 AC 145 ms
12,672 KB
testcase_07 AC 117 ms
12,672 KB
testcase_08 AC 205 ms
12,416 KB
testcase_09 AC 353 ms
12,544 KB
testcase_10 AC 434 ms
12,416 KB
testcase_11 AC 303 ms
12,544 KB
testcase_12 AC 246 ms
12,672 KB
testcase_13 AC 131 ms
12,544 KB
testcase_14 AC 428 ms
12,672 KB
testcase_15 AC 604 ms
12,544 KB
testcase_16 AC 525 ms
12,544 KB
testcase_17 AC 580 ms
12,416 KB
testcase_18 AC 127 ms
12,672 KB
testcase_19 AC 615 ms
12,416 KB
testcase_20 AC 107 ms
12,288 KB
testcase_21 AC 102 ms
12,288 KB
testcase_22 AC 440 ms
12,544 KB
testcase_23 AC 602 ms
12,416 KB
testcase_24 AC 605 ms
12,672 KB
testcase_25 AC 587 ms
12,544 KB
testcase_26 WA -
testcase_27 AC 133 ms
12,544 KB
testcase_28 AC 505 ms
12,544 KB
testcase_29 AC 306 ms
12,672 KB
testcase_30 AC 97 ms
12,416 KB
testcase_31 AC 99 ms
12,160 KB
testcase_32 AC 279 ms
12,672 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:26: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

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
0