結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
TakoKurage
|
| 提出日時 | 2019-08-31 11:19:36 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 5,000 ms |
| コード長 | 451 bytes |
| コンパイル時間 | 146 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-07-01 09:29:55 |
| 合計ジャッジ時間 | 2,298 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
from collections import deque
def main():
N = int(input())
visited = [False] * (N + 1)
visited[1] = True
Q = deque([(1, 1)])
while Q:
n, c = Q.popleft()
if n == N:
print(c)
quit()
d = bin(n).count("1")
for nn in (n + d, n - d):
if 0 < nn <= N and not visited[nn]:
visited[nn] = True
Q.append((nn, c + 1))
print(-1)
main()
TakoKurage