結果

問題 No.3 ビットすごろく
ユーザー Kgm1500
提出日時 2018-04-29 17:51:22
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 756 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-06-27 23:34:06
合計ジャッジ時間 2,031 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    N = int(input())
#     N = s
    is_visited = [False for i in range(N+1)]
    is_visited[1] = True
    is_reached = False
    count = 0

    que = [1]
    while len(que) > 0:
        count += 1
        v_i = que.pop(0)
#         print(v_i, v_i == N, count)
        if v_i == N:
            is_reached = True
            break
        else:
            step = bin(v_i).count("1")
            if v_i+step <= N and not(is_visited[v_i+step]):
                is_visited[v_i+step] = True
                que.append(v_i+step)
            elif v_i-step >= 1 and not(is_visited[v_i-step]):
                is_visited[v_i-step] = True
                que.append(v_i-step)

    if is_reached: return count
    else:          return -1
print(solve())
0