結果

問題 No.3 ビットすごろく
ユーザー LaLa
提出日時 2020-11-23 16:31:34
言語 Ruby
(3.3.0)
結果
AC  
実行時間 77 ms / 5,000 ms
コード長 268 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 11,344 KB
実行使用メモリ 15,524 KB
最終ジャッジ日時 2023-09-14 01:54:47
合計ジャッジ時間 4,278 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
15,100 KB
testcase_01 AC 67 ms
15,228 KB
testcase_02 AC 66 ms
15,040 KB
testcase_03 AC 69 ms
15,324 KB
testcase_04 AC 68 ms
15,264 KB
testcase_05 AC 72 ms
15,224 KB
testcase_06 AC 69 ms
15,172 KB
testcase_07 AC 68 ms
15,256 KB
testcase_08 AC 71 ms
15,524 KB
testcase_09 AC 73 ms
15,344 KB
testcase_10 AC 74 ms
15,420 KB
testcase_11 AC 73 ms
15,300 KB
testcase_12 AC 73 ms
15,468 KB
testcase_13 AC 70 ms
15,276 KB
testcase_14 AC 74 ms
15,316 KB
testcase_15 AC 75 ms
15,296 KB
testcase_16 AC 75 ms
15,340 KB
testcase_17 AC 76 ms
15,440 KB
testcase_18 AC 68 ms
15,164 KB
testcase_19 AC 75 ms
15,340 KB
testcase_20 AC 68 ms
15,316 KB
testcase_21 AC 66 ms
15,224 KB
testcase_22 AC 74 ms
15,296 KB
testcase_23 AC 76 ms
15,412 KB
testcase_24 AC 77 ms
15,520 KB
testcase_25 AC 77 ms
15,328 KB
testcase_26 AC 66 ms
15,272 KB
testcase_27 AC 70 ms
15,228 KB
testcase_28 AC 75 ms
15,284 KB
testcase_29 AC 76 ms
15,464 KB
testcase_30 AC 68 ms
15,120 KB
testcase_31 AC 68 ms
15,160 KB
testcase_32 AC 74 ms
15,416 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N=gets.to_i
dp=Array.new(N+1,-1)

Q=[[1,1]]
until Q.empty?
  u,v=Q.shift
  next if u<1||u>N||dp[u]!=-1
  dp[u]=v
  ua=u+u.to_s(2).count('1')
  ub=u-u.to_s(2).count('1')
  Q.push([ua,v+1]) if dp[ua]==-1 && ua<=N
  Q.push([ub,v+1]) if dp[ub]==-1 && ub>=1
end

puts dp[N]
0