AtCoder-Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub ryusuke920/AtCoder-Library

:heavy_check_mark: Test/yukicoder/0003.test.py

Code

# verification-helper: PROBLEM https://yukicoder.me/problems/no/3

from collections import deque

def main() -> None:

    n = int(input())

    dist = [0] * (n + 1)
    dist[1] = 1

    q = deque([1])
    while q:
        v = q.popleft()
        cnt = 0
        for i in range(60):
            if v >> i & 1:
                cnt += 1

        a = v - cnt
        if 1 <= a <= n:
            if dist[a] == 0:
                dist[a] = dist[v] + 1
                q.append(a)

        b = v + cnt
        if 1 <= b <= n:
            if dist[b] == 0:
                dist[b] = dist[v] + 1
                q.append(b)

    print(dist[-1]) if dist[-1] != 0 else print(-1)


if __name__ == "__main__":
    main()
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/python.py", line 96, in bundle
    raise NotImplementedError
NotImplementedError
Back to top page