結果

問題 No.3 ビットすごろく
ユーザー 9453435994534359
提出日時 2020-11-02 06:55:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 955 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 11,364 KB
最終ジャッジ日時 2023-09-14 01:53:33
合計ジャッジ時間 2,937 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
10,332 KB
testcase_01 AC 36 ms
10,368 KB
testcase_02 AC 35 ms
10,328 KB
testcase_03 AC 39 ms
10,592 KB
testcase_04 AC 36 ms
10,328 KB
testcase_05 AC 46 ms
10,588 KB
testcase_06 AC 39 ms
10,536 KB
testcase_07 AC 38 ms
10,396 KB
testcase_08 AC 44 ms
10,544 KB
testcase_09 AC 51 ms
11,036 KB
testcase_10 AC 53 ms
11,192 KB
testcase_11 AC 48 ms
10,540 KB
testcase_12 AC 44 ms
10,604 KB
testcase_13 AC 38 ms
10,600 KB
testcase_14 AC 52 ms
11,300 KB
testcase_15 AC 56 ms
11,304 KB
testcase_16 AC 55 ms
11,196 KB
testcase_17 AC 55 ms
11,364 KB
testcase_18 AC 36 ms
10,468 KB
testcase_19 AC 56 ms
11,240 KB
testcase_20 AC 34 ms
10,376 KB
testcase_21 AC 34 ms
10,328 KB
testcase_22 AC 52 ms
11,204 KB
testcase_23 AC 56 ms
11,240 KB
testcase_24 AC 56 ms
11,244 KB
testcase_25 AC 56 ms
11,160 KB
testcase_26 AC 34 ms
10,376 KB
testcase_27 AC 37 ms
10,528 KB
testcase_28 AC 53 ms
11,232 KB
testcase_29 AC 49 ms
10,940 KB
testcase_30 AC 33 ms
10,320 KB
testcase_31 AC 33 ms
10,436 KB
testcase_32 AC 45 ms
10,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import heapq
import itertools
import sys
import math
import random
import time
from collections import Counter, deque, defaultdict
from functools import reduce
from operator import xor
from typing import List

mod = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 9)


def lmi():
    return list(map(int, input().split()))


def main():
    N = int(input())
    queue = deque()
    queue.append((1, 1))
    visited = set()
    while queue:
        cur, depth = queue.popleft()
        if cur < 0 or N + 1 <= cur:
            continue
        if cur in visited:
            continue
        if cur == N:
            print(depth)
            return

        visited.add(cur)
        queue.append((cur + f(cur), depth + 1))
        queue.append((cur - f(cur), depth + 1))
    
    print(-1)


def f(num):
    ret = 0
    while num:
        if num % 2 == 1:
            ret += 1
        num >>= 1
    return ret



if __name__ == '__main__':
    main()
0