結果

問題 No.3 ビットすごろく
ユーザー irisAshirisAsh
提出日時 2017-08-14 22:51:37
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 314 ms / 5,000 ms
コード長 628 bytes
コンパイル時間 58 ms
コンパイル使用メモリ 5,216 KB
実行使用メモリ 48,108 KB
最終ジャッジ日時 2023-09-14 00:48:02
合計ジャッジ時間 8,420 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
42,176 KB
testcase_01 AC 75 ms
42,216 KB
testcase_02 AC 76 ms
42,264 KB
testcase_03 AC 150 ms
45,472 KB
testcase_04 AC 81 ms
42,584 KB
testcase_05 AC 164 ms
47,540 KB
testcase_06 AC 103 ms
44,112 KB
testcase_07 AC 90 ms
43,900 KB
testcase_08 AC 132 ms
47,440 KB
testcase_09 AC 203 ms
47,908 KB
testcase_10 AC 245 ms
47,836 KB
testcase_11 AC 187 ms
47,692 KB
testcase_12 AC 158 ms
47,756 KB
testcase_13 AC 94 ms
43,912 KB
testcase_14 AC 236 ms
47,852 KB
testcase_15 AC 311 ms
47,832 KB
testcase_16 AC 281 ms
47,920 KB
testcase_17 AC 301 ms
48,016 KB
testcase_18 AC 93 ms
43,868 KB
testcase_19 AC 314 ms
47,940 KB
testcase_20 AC 78 ms
42,496 KB
testcase_21 AC 77 ms
42,236 KB
testcase_22 AC 239 ms
47,940 KB
testcase_23 AC 312 ms
47,856 KB
testcase_24 AC 312 ms
47,972 KB
testcase_25 AC 309 ms
48,108 KB
testcase_26 AC 75 ms
42,308 KB
testcase_27 AC 97 ms
43,968 KB
testcase_28 AC 273 ms
47,960 KB
testcase_29 AC 190 ms
47,612 KB
testcase_30 AC 79 ms
42,364 KB
testcase_31 AC 78 ms
42,408 KB
testcase_32 AC 179 ms
47,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let i = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')[0]
let a = []
for (let c = 1; c <= i; c++) {
  let n = 0
  c.toString(2).split('').forEach((e) => e === '1' ? n++ : n)
  a.push(n)
}
let q = [0]
let m = [0]
let d = 1
let r = false
while (q.length > 0) {
  if (m.indexOf(a.length - 1) > -1) {
    r = true
    break
  }
  d++
  let t = q.concat()
  q = []
  t.forEach((e) => {
    let f = e + a[e]
    let b = e - a[e]
    if (f < a.length && m.indexOf(f) == -1) {
      m.push(f)
      q.push(f)
    }
    if (b > 0 && m.indexOf(b) == -1) {
      m.push(b)
      q.push(b)
    }
  })
}
console.log(r ? d : -1)
0