結果

問題 No.3 ビットすごろく
ユーザー irisAshirisAsh
提出日時 2017-08-14 21:11:18
言語 JavaScript
(node v21.7.1)
結果
TLE  
実行時間 -
コード長 586 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 5,120 KB
実行使用メモリ 79,048 KB
最終ジャッジ日時 2024-04-21 01:52:32
合計ジャッジ時間 6,805 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
38,400 KB
testcase_01 AC 55 ms
38,784 KB
testcase_02 AC 56 ms
38,400 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

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)
}
const f = (x, y, a, d) => {
  if (x == a.length - 1) return d
  if (x < 0 || x >= a.length) return -1
  if (y.indexOf(x) > -1) return -1
  let m = y.concat()
  m.push(x)
  let r1 = f(x - a[x], m, a, d+1)
  let r2 = f(x + a[x], m, a, d+1)
  if (r1 == -1 && r2 == -1) return -1
  if (r1 == -1) return r2
  if (r2 == -1) return r1
  return r1 > r2 ? r2 : r1
}
console.log(f(0, [], a, 1))
0