結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
kagami
|
| 提出日時 | 2019-07-14 18:39:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 650 bytes |
| コンパイル時間 | 192 ms |
| コンパイル使用メモリ | 82,096 KB |
| 実行使用メモリ | 71,668 KB |
| 最終ジャッジ日時 | 2024-11-24 12:53:41 |
| 合計ジャッジ時間 | 2,880 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / 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))
kagami