結果

問題 No.3 ビットすごろく
ユーザー edash
提出日時 2018-08-19 17:58:17
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 499 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-11-17 18:52:03
合計ジャッジ時間 2,422 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 4 RE * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())

lst = [0]*(n+1)

def f(num,cnt):
    if num==n:
        print(len(cnt))
        return True
    
    step = str(bin(num))[2:].count("1")
    fowd_n = num+step
    back_n = num-step
    
    if fowd_n<=n and fowd_n not in cnt:
        cnt.append(fowd_n)
        if f(fowd_n,cnt):
            return True
    if back_n>0 and back_n not in cnt:
        cnt.append(back_n)
        if f(back_n,cnt):
            return True
    return False
        
if f(1,[1])==False:
        print(-1)
0