結果

問題 No.3 ビットすごろく
ユーザー yoza
提出日時 2016-12-12 22:25:42
言語 Vim script
(v9.1)
結果
WA  
実行時間 -
コード長 990 bytes
コンパイル時間 69 ms
コンパイル使用メモリ 6,948 KB
実行使用メモリ 11,964 KB
最終ジャッジ日時 2024-11-29 18:02:47
合計ジャッジ時間 6,090 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

function! s:output()
  let this = {'lines': []}

  function! this.append(line) abort
    call add(self.lines, a:line)
  endfunction

  function! this.build() abort
    return join(self.lines, "\n")
  endfunction

  return this
endfunction

function! s:main(input) abort
  let o = s:output()

  let n = str2nr(a:input[0])
  let next = 1
  let cells = {'1': 1}
  let q = [1]
  let r = -1
  while len(q) > 0
    let c = remove(q, 0)
    let b = printf('%b', c)
    let move = len(b) - len(substitute(b, '1', '', 'g'))

    let left = c - move
    let right = c + move

    if left > 0 && !has_key(cells, left)
      let cells[left] = cells[c] + 1
      call add(q, left)
    endif

    if right < n && !has_key(cells, right)
      let cells[right] = cells[c] + 1
      call add(q, right)
    endif

    if right == n
      let r = cells[c] + 1
      break
    endif
  endwhile

  call o.append(r)
  return o.build()
endfunction

let s:input = getline(1, '$')
enew
put =s:main(s:input)
2,$print
0