結果

問題 No.3 ビットすごろく
ユーザー LaLa
提出日時 2020-11-23 16:30:16
言語 Ruby
(3.2.2)
結果
WA  
実行時間 -
コード長 257 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 11,236 KB
実行使用メモリ 19,452 KB
最終ジャッジ日時 2023-09-30 23:54:53
合計ジャッジ時間 12,576 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
19,452 KB
testcase_01 AC 83 ms
15,208 KB
testcase_02 AC 85 ms
15,112 KB
testcase_03 AC 117 ms
15,240 KB
testcase_04 AC 91 ms
15,336 KB
testcase_05 AC 599 ms
16,140 KB
testcase_06 AC 122 ms
15,292 KB
testcase_07 AC 102 ms
15,132 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
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 #

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]=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