結果

問題 No.3 ビットすごろく
ユーザー suppy193suppy193
提出日時 2015-06-17 13:30:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 100 ms / 5,000 ms
コード長 451 bytes
コンパイル時間 40 ms
コンパイル使用メモリ 11,552 KB
実行使用メモリ 15,844 KB
最終ジャッジ日時 2023-09-13 23:14:10
合計ジャッジ時間 4,250 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,088 KB
testcase_01 AC 78 ms
15,236 KB
testcase_02 AC 77 ms
15,128 KB
testcase_03 AC 87 ms
15,356 KB
testcase_04 AC 81 ms
15,016 KB
testcase_05 AC 89 ms
15,828 KB
testcase_06 AC 87 ms
15,380 KB
testcase_07 AC 80 ms
15,476 KB
testcase_08 AC 86 ms
15,492 KB
testcase_09 AC 93 ms
15,800 KB
testcase_10 AC 95 ms
15,660 KB
testcase_11 AC 90 ms
15,636 KB
testcase_12 AC 89 ms
15,452 KB
testcase_13 AC 82 ms
15,300 KB
testcase_14 AC 94 ms
15,808 KB
testcase_15 AC 98 ms
15,584 KB
testcase_16 AC 96 ms
15,844 KB
testcase_17 AC 98 ms
15,788 KB
testcase_18 AC 86 ms
15,328 KB
testcase_19 AC 100 ms
15,596 KB
testcase_20 AC 83 ms
15,128 KB
testcase_21 AC 81 ms
15,132 KB
testcase_22 AC 98 ms
15,772 KB
testcase_23 AC 99 ms
15,648 KB
testcase_24 AC 99 ms
15,620 KB
testcase_25 AC 99 ms
15,728 KB
testcase_26 AC 77 ms
15,004 KB
testcase_27 AC 84 ms
15,520 KB
testcase_28 AC 97 ms
15,556 KB
testcase_29 AC 91 ms
15,780 KB
testcase_30 AC 80 ms
15,184 KB
testcase_31 AC 83 ms
15,044 KB
testcase_32 AC 94 ms
15,672 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.chomp.to_i
@memo = Hash.new(0)
step = 1
set = [1]
@memo[1] = 1
while set.length > 0
	next_set = []
	step += 1
	set.each do |i|
		move = i.to_s(2).scan('1').length
		if i + move <= n && !@memo.key?(i + move)
			@memo[i + move] = step
			next_set << i + move
		end
		if i - move > 1 && !@memo.key?(i - move)
			@memo[i - move] = step
			next_set << i - move
		end
	end
	set = next_set
end
unless @memo.key?(n)
	puts '-1'
else
	puts @memo[n]
end
0