結果

問題 No.3 ビットすごろく
ユーザー niyarin
提出日時 2017-03-15 13:21:52
言語 Python2
(2.7.18)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 461 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-01 08:37:09
合計ジャッジ時間 1,823 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

N = input()


d = []
used = []
for i in range(10001):
    d.append(bin(i).count("1"))
    used.append(0)

que = [(1,1)]
ans = -1
while que:
    pos,cnt = que.pop(0)
    if pos == N:
        ans = cnt
        break
    left = pos-d[pos]
    right = pos + d[pos]

    if left>0 and not used[left]:
        used[left] = 1
        que.append((left,cnt+1))
    if right < N+1 and not used[right]:
        used[right] = 1
        que.append((right,cnt+1))

print ans
0