結果

問題 No.3 ビットすごろく
ユーザー togatogatogatoga
提出日時 2015-08-15 07:29:14
言語 Python2
(2.7.18)
結果
AC  
実行時間 94 ms / 5,000 ms
コード長 436 bytes
コンパイル時間 61 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-07-01 07:28:51
合計ジャッジ時間 3,015 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

from Queue import Queue
import sys
N = input()
q  = Queue()
q.put([1, 0])
visit = set()
while (q.empty() == False):
    pos = q.get()
    if (pos[0] <= 0 or pos[0] >= N + 1):
        continue
    if (pos[0] == N):
        print pos[1] + 1
        sys.exit(0)
    if (pos[0] in visit):
        continue
    visit.add(pos[0])
    x = bin(pos[0]).count("1")
    q.put([pos[0] + x, pos[1] + 1])
    q.put([pos[0] - x, pos[1] + 1])
print -1
0