結果

問題 No.3 ビットすごろく
ユーザー jcm_2jcm_2
提出日時 2019-08-14 01:19:00
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 279 ms / 5,000 ms
コード長 493 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 5,216 KB
実行使用メモリ 49,720 KB
最終ジャッジ日時 2023-09-14 01:25:21
合計ジャッジ時間 7,293 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
42,236 KB
testcase_01 AC 71 ms
42,160 KB
testcase_02 AC 72 ms
42,236 KB
testcase_03 AC 168 ms
46,548 KB
testcase_04 AC 77 ms
43,196 KB
testcase_05 AC 152 ms
48,040 KB
testcase_06 AC 103 ms
47,580 KB
testcase_07 AC 91 ms
47,560 KB
testcase_08 AC 137 ms
47,996 KB
testcase_09 AC 182 ms
47,596 KB
testcase_10 AC 258 ms
48,296 KB
testcase_11 AC 187 ms
47,660 KB
testcase_12 AC 148 ms
47,804 KB
testcase_13 AC 96 ms
47,660 KB
testcase_14 AC 237 ms
48,096 KB
testcase_15 AC 278 ms
47,776 KB
testcase_16 AC 269 ms
47,820 KB
testcase_17 AC 263 ms
47,804 KB
testcase_18 AC 88 ms
47,536 KB
testcase_19 AC 279 ms
47,724 KB
testcase_20 AC 78 ms
42,884 KB
testcase_21 AC 74 ms
42,324 KB
testcase_22 AC 235 ms
47,676 KB
testcase_23 AC 268 ms
47,684 KB
testcase_24 AC 276 ms
47,564 KB
testcase_25 AC 274 ms
47,776 KB
testcase_26 AC 74 ms
42,240 KB
testcase_27 AC 101 ms
47,564 KB
testcase_28 AC 254 ms
49,720 KB
testcase_29 AC 177 ms
47,680 KB
testcase_30 AC 76 ms
42,428 KB
testcase_31 AC 73 ms
42,480 KB
testcase_32 AC 158 ms
47,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function Main(input) {
  function countTarget(str, target) {
    return (str.match(new RegExp(target, "g")) || []).length;
  }
  function rec(num, c) {
    if (array[num] && array[num] <= c || num > N) return
    array[num] = c
    const k = countTarget(num.toString(2), "1")
    rec(num + k, c + 1)
    rec(num - k, c + 1)
  }
  const N = parseInt(input.trim())
  let array = [-1, 1]
  rec(2, 2)
  console.log(array[N] ? array[N] : -1)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))
0