結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
URechaRecha
|
| 提出日時 | 2019-08-22 10:56:39 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 632 bytes |
| コンパイル時間 | 92 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-10-12 01:57:42 |
| 合計ジャッジ時間 | 3,003 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 15 |
ソースコード
import heapq
def bitsugoroku(N,cur=1,path=None):
h = []
heapq.heappush(h,[N,cur,[]])
while len(h) > 0:
N,cur,path = heapq.heappop(h)
if cur not in path:
path.append(cur)
if N == cur:
return len(path)
a = str(bin(cur)).count("1")#移動する数
if (cur + a <= N) and (cur + a) not in path:
cur +=a
heapq.heappush(h,[N,cur,path])
if (cur - a > 1) and (cur -a) not in path:
cur -=a
heapq.heappush(h,[N,cur,path])
return -1
N = int(input())
print(bitsugoroku(N))
URechaRecha