結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2020-06-06 00:31:32 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 43 ms / 5,000 ms |
コード長 | 657 bytes |
コンパイル時間 | 90 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-07-01 09:50:12 |
合計ジャッジ時間 | 2,268 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
# Problem 3 - ビットすごろく from collections import deque def calc_bin(num): return bin(num).count("1") # input N = int(input()) # initialization masu = [-1]*(N+1) masu[1] = 1 queue = deque([1]) # bfs search while len(queue)>0: cur_pos = queue.popleft() cur_nxt = calc_bin(cur_pos) # left move if cur_pos-cur_nxt>0 and masu[cur_pos-cur_nxt]==-1: masu[cur_pos-cur_nxt] = masu[cur_pos] + 1 queue.append(cur_pos-cur_nxt) # right move if cur_pos+cur_nxt<N+1 and masu[cur_pos+cur_nxt]==-1: masu[cur_pos+cur_nxt] = masu[cur_pos] + 1 queue.append(cur_pos+cur_nxt) # output print(masu[N])