結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2022-12-07 19:14:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 88 ms / 5,000 ms |
コード長 | 476 bytes |
コンパイル時間 | 178 ms |
コンパイル使用メモリ | 81,872 KB |
実行使用メモリ | 73,116 KB |
最終ジャッジ日時 | 2024-10-14 00:01:10 |
合計ジャッジ時間 | 2,883 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
from collections import deque, defaultdict N = int(input()) bin_N = bin(N)[2:] dist = defaultdict(lambda:-1) dist[1] = 1 Q = deque() Q.append(1) while len(Q) > 0: x = Q.popleft() bin_x = bin(x) bin_count = bin_x.count('1') count_list = [x + bin_count,x - bin_count] for i in count_list: if (1<=i<=N): if dist[i]==-1: dist[i] = dist[x]+1 Q.append(i) else: continue print(dist[N])