結果
問題 | No.3 ビットすごろく |
ユーザー | piconic_X |
提出日時 | 2016-08-13 22:02:21 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 37 ms / 5,000 ms |
コード長 | 763 bytes |
コンパイル時間 | 88 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-07-01 08:02:28 |
合計ジャッジ時間 | 2,203 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
def search(N): history = set() queue = [0] res = -1 time = 1 while queue: next_queue = [] for pos in queue: if pos == N-1: res = time break else: bitnum = bin(pos+1).count('1') posR = pos + bitnum posL = pos - bitnum if posR < N and not posR in history: history.add(posR) next_queue.append(posR) if posL > 0 and not posL in history: history.add(posL) next_queue.append(posL) time += 1 queue = next_queue return res def main(): N = int(input()) res = search(N) print(res) main()