結果
| 問題 |
No.3 ビットすごろく
|
| ユーザー |
|
| 提出日時 | 2022-02-13 03:07:30 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 5,000 ms |
| コード長 | 506 bytes |
| コンパイル時間 | 74 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-06-29 05:23:37 |
| 合計ジャッジ時間 | 1,893 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
from collections import deque
def bit(x):
x = bin(x)
x = x.count('1')
return x
def bit_fb(x):
a = x - bit(x)
b = x + bit(x)
return a,b
N = int(input())
A = [0] * (N+1)
A[1] = 1
B = deque()
B.append(1)
while B:
C = B.popleft()
if C == N:
print(A[C])
break
D,E = bit_fb(C)
if 0 < D <= N and A[D] == 0:
B.append(D)
A[D] = A[C] + 1
if 0 < E <= N and A[E] == 0:
B.append(E)
A[E] = A[C] + 1
if A[N] == 0:
print(-1)