結果
問題 | No.3 ビットすごろく |
ユーザー |
![]() |
提出日時 | 2016-12-12 22:28:08 |
言語 | Vim script (v9.1) |
結果 |
AC
|
実行時間 | 303 ms / 5,000 ms |
コード長 | 988 bytes |
コンパイル時間 | 39 ms |
コンパイル使用メモリ | 6,684 KB |
実行使用メモリ | 12,160 KB |
最終ジャッジ日時 | 2024-07-01 08:11:47 |
合計ジャッジ時間 | 7,034 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
function! s:output()let this = {'lines': []}function! this.append(line) abortcall add(self.lines, a:line)endfunctionfunction! this.build() abortreturn join(self.lines, "\n")endfunctionreturn thisendfunctionfunction! s:main(input) abortlet o = s:output()let n = str2nr(a:input[0])let cells = {'1': 1}let q = [1]let r = n == 1 ? 1 : -1while len(q) > 0let c = remove(q, 0)let b = printf('%b', c)let move = len(b) - len(substitute(b, '1', '', 'g'))let left = c - movelet right = c + moveif left > 0 && !has_key(cells, left)let cells[left] = cells[c] + 1call add(q, left)endifif right < n && !has_key(cells, right)let cells[right] = cells[c] + 1call add(q, right)endifif right == nlet r = cells[c] + 1breakendifendwhilecall o.append(r)return o.build()endfunctionlet s:input = getline(1, '$')enewput =s:main(s:input)2,$print