結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-05-19 13:16:50 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 870 bytes |
| 記録 | |
| コンパイル時間 | 717 ms |
| コンパイル使用メモリ | 20,828 KB |
| 実行使用メモリ | 30,840 KB |
| 最終ジャッジ日時 | 2026-03-17 10:25:21 |
| 合計ジャッジ時間 | 131,674 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 TLE * 19 |
ソースコード
n = int(input())
def count_1(n):
return list((bin(n)))[2:].count("1")
class BiSugoroku():
def __init__(self, n):
self.n = n
self.plus = self.n + count_1(n)
self.minus = self.n - count_1(n)
q = [BiSugoroku(1)]
visited = [1]
step = 0
next_flag = True
find = False
while next_flag:
next_flag = False
step += 1
for b in q[:]:
if b.n == n:
next_flag = False
find = True
break
else:
if b.plus <= n and not (b.plus in visited):
q.append(BiSugoroku(b.plus))
visited.append(b.plus)
next_flag = True
if 0 < b.minus and not (b.minus in visited):
q.append(BiSugoroku(b.minus))
visited.append(b.minus)
next_flag = True
else:
print(step if find else -1)