結果

問題 No.3 ビットすごろく
ユーザー terasaterasa
提出日時 2022-06-03 14:27:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 75 ms / 5,000 ms
コード長 1,183 bytes
コンパイル時間 564 ms
コンパイル使用メモリ 81,768 KB
実行使用メモリ 77,376 KB
最終ジャッジ日時 2023-10-21 01:28:17
合計ジャッジ時間 3,533 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,728 KB
testcase_01 AC 44 ms
55,728 KB
testcase_02 AC 43 ms
55,728 KB
testcase_03 AC 57 ms
68,660 KB
testcase_04 AC 48 ms
61,964 KB
testcase_05 AC 61 ms
72,756 KB
testcase_06 AC 57 ms
68,660 KB
testcase_07 AC 57 ms
66,600 KB
testcase_08 AC 58 ms
70,708 KB
testcase_09 AC 64 ms
73,816 KB
testcase_10 AC 68 ms
77,076 KB
testcase_11 AC 58 ms
73,044 KB
testcase_12 AC 59 ms
72,756 KB
testcase_13 AC 55 ms
68,656 KB
testcase_14 AC 68 ms
77,048 KB
testcase_15 AC 67 ms
77,292 KB
testcase_16 AC 66 ms
77,184 KB
testcase_17 AC 65 ms
77,376 KB
testcase_18 AC 55 ms
68,656 KB
testcase_19 AC 68 ms
77,316 KB
testcase_20 AC 46 ms
55,728 KB
testcase_21 AC 42 ms
55,728 KB
testcase_22 AC 66 ms
77,156 KB
testcase_23 AC 67 ms
77,316 KB
testcase_24 AC 75 ms
77,312 KB
testcase_25 AC 68 ms
77,296 KB
testcase_26 AC 41 ms
55,728 KB
testcase_27 AC 56 ms
68,656 KB
testcase_28 AC 67 ms
77,156 KB
testcase_29 AC 61 ms
73,184 KB
testcase_30 AC 43 ms
55,728 KB
testcase_31 AC 42 ms
55,728 KB
testcase_32 AC 61 ms
72,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


N = int(input())

E = [[] for _ in range(N + 1)]
for i in range(1, N + 1):
    b = bin(i).count('1')
    if i - b > 0:
        E[i].append(i - b)
    if i + b <= N:
        E[i].append(i + b)

INF = 1 << 30
C = [INF] * (N + 1)
C[1] = 1
dq = deque([1])
while len(dq) > 0:
    v = dq.popleft()
    for d in E[v]:
        if C[d] > C[v] + 1:
            C[d] = C[v] + 1
            dq.append(d)
print(C[N] if C[N] < INF else -1)
0