結果
問題 | No.3 ビットすごろく |
ユーザー |
![]() |
提出日時 | 2017-01-16 13:52:20 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 37 ms / 5,000 ms |
コード長 | 653 bytes |
コンパイル時間 | 120 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,520 KB |
最終ジャッジ日時 | 2024-07-01 08:16:28 |
合計ジャッジ時間 | 2,161 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
def sugoroku(n): visited = set([1]) cnt = 1 que = [1] while len(que) > 0: if n in visited: return cnt new_que = [] for now in que: b = bin(now).count('1') flont = now + b back = now - b if 0 < flont <= n and flont not in visited: new_que.append(flont) visited.add(flont) if 0 < back <= n and back not in visited: new_que.append(back) visited.add(back) cnt += 1 que = new_que return -1 if __name__ == "__main__": n = int(input()) print(sugoroku(n))