結果

問題 No.3 ビットすごろく
ユーザー gemmarogemmaro
提出日時 2020-04-28 22:51:01
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 374 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 72,628 KB
最終ジャッジ日時 2024-05-04 10:18:52
合計ジャッジ時間 8,653 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
12,160 KB
testcase_01 AC 72 ms
12,288 KB
testcase_02 AC 73 ms
12,160 KB
testcase_03 AC 1,148 ms
66,620 KB
testcase_04 AC 87 ms
15,104 KB
testcase_05 TLE -
testcase_06 AC 1,392 ms
60,268 KB
testcase_07 AC 127 ms
22,784 KB
testcase_08 AC 423 ms
52,736 KB
testcase_09 AC 899 ms
66,000 KB
testcase_10 AC 1,165 ms
65,824 KB
testcase_11 AC 780 ms
65,876 KB
testcase_12 TLE -
testcase_13 AC 851 ms
62,424 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

def solve # rubocop:todo Metrics/MethodLength
  p = [1]

  (1..N).each do |i|
    n = []
    p.each do |x|
      y = x + C[x]
      return i + 1 if y == N

      n << y if y < N

      z = x - C[x]
      n << z if z > 1
    end
    p = n.uniq
  end

  -1
end

N = gets.to_i

C = (0..N).map { _1.digits(2).count(1) }
RESULT = solve

puts RESULT
0