結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  H20 | 
| 提出日時 | 2020-12-01 22:49:10 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 69 ms / 5,000 ms | 
| コード長 | 557 bytes | 
| コンパイル時間 | 196 ms | 
| コンパイル使用メモリ | 81,792 KB | 
| 実行使用メモリ | 74,292 KB | 
| 最終ジャッジ日時 | 2024-07-01 10:01:09 | 
| 合計ジャッジ時間 | 3,434 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
from collections import deque
N = int(input())
L=[]
[L.append([])for _ in range(N+1)]
PASS = [0]*(N+1)
for i in range(N+1):
    cnt = format(i, 'b').count('1')
    if i-cnt >=1:
        L[i].append(i-cnt)
    if i+cnt <=N:
        L[i].append(i+cnt)
q = deque()
qcnt = deque()
q.append(1)
qcnt.append(1)
while len(q) !=0:
    temp = q.popleft()
    cnt = qcnt.popleft()
    if temp ==N:
        print(cnt)
        exit()
    if PASS[temp]==0:
        PASS[temp]=1
        for a in L[temp]:
            q.append(a)
            qcnt.append(cnt+1)
print(-1)
            
            
            
        