結果

問題 No.3 ビットすごろく
ユーザー iceEiji2iceEiji2
提出日時 2016-11-22 15:14:39
言語 Ruby
(3.3.0)
結果
AC  
実行時間 95 ms / 5,000 ms
コード長 623 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 11,244 KB
実行使用メモリ 15,776 KB
最終ジャッジ日時 2023-09-14 00:13:19
合計ジャッジ時間 4,327 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,092 KB
testcase_01 AC 82 ms
15,360 KB
testcase_02 AC 83 ms
15,224 KB
testcase_03 AC 86 ms
15,300 KB
testcase_04 AC 83 ms
15,188 KB
testcase_05 AC 89 ms
15,712 KB
testcase_06 AC 87 ms
15,568 KB
testcase_07 AC 87 ms
15,304 KB
testcase_08 AC 87 ms
15,484 KB
testcase_09 AC 90 ms
15,592 KB
testcase_10 AC 91 ms
15,600 KB
testcase_11 AC 90 ms
15,728 KB
testcase_12 AC 89 ms
15,620 KB
testcase_13 AC 86 ms
15,116 KB
testcase_14 AC 90 ms
15,628 KB
testcase_15 AC 93 ms
15,620 KB
testcase_16 AC 91 ms
15,640 KB
testcase_17 AC 92 ms
15,536 KB
testcase_18 AC 86 ms
15,224 KB
testcase_19 AC 93 ms
15,776 KB
testcase_20 AC 83 ms
15,128 KB
testcase_21 AC 82 ms
15,152 KB
testcase_22 AC 92 ms
15,644 KB
testcase_23 AC 94 ms
15,680 KB
testcase_24 AC 94 ms
15,568 KB
testcase_25 AC 95 ms
15,532 KB
testcase_26 AC 84 ms
15,168 KB
testcase_27 AC 85 ms
15,352 KB
testcase_28 AC 91 ms
15,532 KB
testcase_29 AC 91 ms
15,776 KB
testcase_30 AC 84 ms
15,144 KB
testcase_31 AC 85 ms
15,012 KB
testcase_32 AC 90 ms
15,724 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i

result = -1
queue = [{pos: 1, time: 1}]
check = Array.new(N+1, false)
check[1] = true

while queue.length > 0 do
  current = queue.shift
  if current[:pos] == N
    result = current[:time]
    break
  end
  move = current[:pos].to_s(2).count("1")
  if current[:pos] - move > 0 && !check[current[:pos] - move]
    queue << {pos: current[:pos] - move, time: current[:time] + 1}
    check[current[:pos] - move] = true
  end
  if current[:pos] + move <= N && !check[current[:pos] + move]
    queue << {pos: current[:pos] + move, time: current[:time] + 1}
    check[current[:pos] + move] = true
  end
end
p result
0