結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-08-13 21:48:22 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 754 bytes |
コンパイル時間 | 96 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 23,248 KB |
最終ジャッジ日時 | 2024-11-07 16:32:29 |
合計ジャッジ時間 | 18,815 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 WA * 4 TLE * 1 -- * 17 |
ソースコード
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: history.add(pos) val = pos+1 bitnum = bin(val).count('1') posR = pos + bitnum posL = pos - bitnum if posR < N and not posR in history: next_queue.append(posR) if posL > 0 and not posL in history: next_queue.append(posL) time += 1 queue = next_queue return res def main(): N = int(input()) res = search(N) print(res) main()