結果

問題 No.3 ビットすごろく
コンテスト
ユーザー HIROPON87069639
提出日時 2016-03-08 23:54:32
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 423 ms / 5,000 ms
コード長 732 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 133 ms
コンパイル使用メモリ 77,348 KB
最終ジャッジ日時 2025-12-03 19:38:10
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# -*- coding: utf-8 -*-
from collections import Counter
from collections import deque

N = input()
Blist = [ 0 for i in range(N)]
for i in range(N):
    tmp = Counter(bin(i+1))
    Blist[i] = tmp["1"]

#幅優先探索
openlist = deque()
closelist = deque()
cntlist = deque()
rlist = deque()
openlist.append(0)
cntlist.append(1)
while len(openlist) != 0:
    point = openlist.popleft()
    cnt = cntlist.popleft()
    if point == N-1:
        print cnt
        exit()
    elif -1 < point < N-1 and closelist.count(point) == 0:
        cnt += 1
        openlist.append(point + Blist[point])
        openlist.append(point - Blist[point])
        closelist.append(point)
        cntlist.append(cnt)
        cntlist.append(cnt)
print -1
0