結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
URechaRecha
|
| 提出日時 | 2019-08-22 11:40:56 |
| 言語 | Python3 (3.14.3 + numpy 2.4.2 + scipy 1.17.0) |
| 結果 |
AC
|
| 実行時間 | 1,022 ms / 5,000 ms |
| コード長 | 711 bytes |
| 記録 | |
| コンパイル時間 | 579 ms |
| コンパイル使用メモリ | 20,956 KB |
| 実行使用メモリ | 15,368 KB |
| 最終ジャッジ日時 | 2026-03-22 06:55:34 |
| 合計ジャッジ時間 | 16,413 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
import heapq
def bitsugoroku(N,cur=1,path=None):
h = []
completed=[]
heapq.heappush(h,[N,cur,[]])
while len(h) > 0:
h.sort(key=lambda x:len(x[2]))
N,cur,path = heapq.heappop(h)
if cur not in completed:
path.append(cur)
completed.append(cur)
if N == cur:
return len(path)
a = str(bin(cur)).count("1")#移動する数
if (cur + a <= N) and ((cur + a) not in completed):
heapq.heappush(h,[N,cur+a,path.copy()])
if (cur - a > 1) and ((cur -a) not in completed):
heapq.heappush(h,[N,cur-a,path.copy()])
return -1
N = int(input())
print(bitsugoroku(N))
URechaRecha