結果

問題 No.3 ビットすごろく
ユーザー suppy193suppy193
提出日時 2015-06-17 13:24:28
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 448 bytes
コンパイル時間 40 ms
コンパイル使用メモリ 11,244 KB
実行使用メモリ 15,600 KB
最終ジャッジ日時 2023-09-21 09:16:11
合計ジャッジ時間 4,182 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
15,340 KB
testcase_01 AC 80 ms
15,132 KB
testcase_02 AC 82 ms
15,124 KB
testcase_03 AC 85 ms
15,160 KB
testcase_04 AC 85 ms
15,312 KB
testcase_05 AC 86 ms
15,168 KB
testcase_06 AC 86 ms
15,212 KB
testcase_07 AC 85 ms
15,132 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 83 ms
15,088 KB
testcase_13 AC 83 ms
15,144 KB
testcase_14 AC 87 ms
15,376 KB
testcase_15 AC 88 ms
15,500 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 86 ms
15,276 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 81 ms
15,224 KB
testcase_22 AC 86 ms
15,440 KB
testcase_23 AC 87 ms
15,236 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 83 ms
15,300 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 81 ms
15,128 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
		elsif 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