結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2020-06-06 00:12:43 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 67 ms / 5,000 ms |
コード長 | 774 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,776 KB |
最終ジャッジ日時 | 2024-07-01 09:50:07 |
合計ジャッジ時間 | 2,834 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
from collections import dequeimport copyimport mathN = int(input())if N == 1:print(1)else:ans, already, que = 1, set([1]), deque([1])while len(que) > 0:nque = deque()while len(que) > 0:n = que.popleft()k, step = n, 0while k > 0:step += k % 2k >>= 1if n - step >= 1 and n - step not in already:nque.append(n - step)already.add(n - step)if n + step < N and n + step not in already:nque.append(n + step)already.add(n + step)elif n + step == N:print(ans + 1)exit()que = copy.copy(nque)ans += 1print(-1)