結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2019-01-09 18:01:57 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 875 bytes |
コンパイル時間 | 155 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-11-24 00:57:45 |
合計ジャッジ時間 | 2,420 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 WA * 22 |
ソースコード
import queue import sys INF = 1000000000 n = int(input()) d = [INF for i in range(n)] visited=[False for i in range(n)] dx = [-1, 1] def calk_walk(n): nn = bin(n) count = 0 for i in range(len(nn)): if nn[i] == '1': count += 1 return count def bfs(p): q = queue.Queue() q.put(p) d[p] = 0 visited[p] = True while not q.empty(): check = q.get() if visited[check]: continue if check == n-1: break for i in range(2): np = check + calk_walk(check+1) * dx[i] if 0 <= np and np < n: q.put(np) d[np] = d[check] + 1 visited[np] = True print(check) return d[n - 1] if bfs(0) == INF: print(-1) sys.exit() print(bfs(0) + 1)