結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
1235486527
|
| 提出日時 | 2019-11-27 11:47:22 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 70 ms / 5,000 ms |
| コード長 | 414 bytes |
| コンパイル時間 | 77 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2024-07-01 09:33:28 |
| 合計ジャッジ時間 | 2,718 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
from queue import Queue
def culc_num_of_bits(bits):
return bin(bits).count('1')
N = int(input())
m = [-1 for i in range(N+1)]
m[1] = 1
Q = Queue()
Q.put(1)
while not Q.empty():
c = Q.get()
b = culc_num_of_bits(c)
if c + b <= N and m[c + b] == -1:
m[c + b] = m[c] + 1
Q.put(c + b)
if c - b > 0 and m[c - b] == -1:
m[c - b] = m[c] + 1
Q.put(c - b)
print(m[N])
1235486527