結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2019-07-14 18:35:58 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 650 bytes |
コンパイル時間 | 218 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-11-24 12:51:26 |
合計ジャッジ時間 | 3,470 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
import sys sys.setrecursionlimit(100000) N = int(input()) visited = [0] * N def bfs(visited, now, ans): if now == (N - 1): return ans if sum(visited) == N: return -1 visited[now] = 1 tmp = bin(now + 1) count = 0 for i in tmp: if i == '1': count += 1 if now + count < N and visited[now + count] == 0: return bfs(visited, now + count, ans + 1) if 0 < now - count and visited[now - count] == 0: return bfs(visited, now - count, ans + 1) return -1 print(bfs(visited, 0, 1))