結果

問題 No.3 ビットすごろく
ユーザー GrayCoder
提出日時 2018-06-26 23:54:15
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 767 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-06-30 23:00:18
合計ジャッジ時間 2,551 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
from sys import stdin, stdout
input = lambda: stdin.readline().rstrip()
write = stdout.write

def bitCount(i):
    ret = 0
    while i:
        i &= i - 1
        ret += 1
    return ret

def main():
    N = int(input())

    que = deque([1])
    grid = [i for i in range(N + 1)]
    move = [None for _ in [0] * (N + 1)]
    move[1] = 1
    cnt = 1
    while que:
        flag = False
        n = que.popleft()
        i = bitCount(grid[n])
        for j in (n + i, n - i):
            if 0 < j <= N and move[j] is None:
                que.append(j)
                move[j] = cnt + 1
                flag = True
        if flag:
            cnt += 1

    if move[-1] is None:
        print(-1)
    else:
        print(move[-1])

main()
0