結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2019-08-24 08:40:03 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 981 ms / 5,000 ms |
コード長 | 538 bytes |
コンパイル時間 | 104 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-07-01 09:28:47 |
合計ジャッジ時間 | 13,589 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
from collections import dequedef bitCount(n):return bin(n).count("1")N = int(input())Node = (1,1)List = [1]Queue = deque([Node])while Queue:n,count = Queue.popleft()if n == N:print(count)exit()bit_count = bitCount(n)if n+bit_count <= N and n + bit_count not in List:List.append(n+bit_count)Queue.append((n+bit_count,count + 1))if n-bit_count > 1 and n - bit_count not in List:List.append(n-bit_count)Queue.append((n-bit_count,count + 1))print(-1)