結果

問題 No.3 ビットすごろく
ユーザー tachyon777
提出日時 2020-02-13 12:49:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 537 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 82,580 KB
実行使用メモリ 80,332 KB
最終ジャッジ日時 2024-10-05 15:32:28
合計ジャッジ時間 5,208 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
lst1 = []
for i in range(1,100001):
    dig = len(bin(i))-2
    res = 0
    for j in range(dig):
        if i >> j & 1:
            res += 1
    lst1.append(res)

visited = [0]*(n+1)
ret = 10**9
def bfs(now,ans):
    global ret
    if now == n-1:
        ret = min(ret,ans)
        return
    if now > n or now < 0:
        return
    if visited[now] == 1:
        return
    visited[now] = 1
    bfs(now+lst1[now],ans+1)
    bfs(now-lst1[now],ans+1)
    return ret if ret < 10**9 else -1
    
print(bfs(0,1))
    
    
0