結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
mottodora
|
| 提出日時 | 2016-10-21 16:43:24 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 702 bytes |
| コンパイル時間 | 81 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,648 KB |
| 最終ジャッジ日時 | 2024-11-23 16:47:14 |
| 合計ジャッジ時間 | 2,461 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 22 |
ソースコード
from collections import defaultdict
memo = {1:1}
def sumbinary(n):
if n == 0:
return 0
elif n % 2 == 0:
return sumbinary(n//2)
else:
return sumbinary(n//2) + 1
target = int(input())
Q = [(1, 1)]
while True:
if len(Q) == 0:
result = -1
break
else:
now, walk = Q.pop(0)
if now == target:
result = walk
break
d = sumbinary(now)
if 0 < now-d < target and not(now-d in memo):
memo[now-d] = walk+1
Q.append((now-d, walk+1))
if 0 < now+d < target and not(now+d in memo):
memo[now+d] = walk+1
Q.append((now+d, walk+1))
print(result)
mottodora