結果

問題 No.3 ビットすごろく
ユーザー siganaisiganai
提出日時 2022-05-26 14:33:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 1,001 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 81,588 KB
実行使用メモリ 70,520 KB
最終ジャッジ日時 2023-10-20 19:26:36
合計ジャッジ時間 3,504 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
63,368 KB
testcase_01 AC 57 ms
63,368 KB
testcase_02 AC 56 ms
63,368 KB
testcase_03 AC 81 ms
66,364 KB
testcase_04 AC 60 ms
65,420 KB
testcase_05 AC 71 ms
70,520 KB
testcase_06 AC 64 ms
66,364 KB
testcase_07 AC 63 ms
66,364 KB
testcase_08 AC 68 ms
68,452 KB
testcase_09 AC 71 ms
70,520 KB
testcase_10 AC 70 ms
70,520 KB
testcase_11 AC 70 ms
70,520 KB
testcase_12 AC 69 ms
70,508 KB
testcase_13 AC 63 ms
66,364 KB
testcase_14 AC 71 ms
70,520 KB
testcase_15 AC 71 ms
70,520 KB
testcase_16 AC 72 ms
70,520 KB
testcase_17 AC 73 ms
70,520 KB
testcase_18 AC 64 ms
66,364 KB
testcase_19 AC 71 ms
70,520 KB
testcase_20 AC 58 ms
63,372 KB
testcase_21 AC 58 ms
63,372 KB
testcase_22 AC 70 ms
70,520 KB
testcase_23 AC 71 ms
70,520 KB
testcase_24 AC 71 ms
70,520 KB
testcase_25 AC 71 ms
70,520 KB
testcase_26 AC 58 ms
63,372 KB
testcase_27 AC 64 ms
66,364 KB
testcase_28 AC 72 ms
70,520 KB
testcase_29 AC 71 ms
70,520 KB
testcase_30 AC 58 ms
63,372 KB
testcase_31 AC 59 ms
63,372 KB
testcase_32 AC 71 ms
70,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
from heapq import *
import functools

mod=10 ** 9 + 7

import sys
input = sys.stdin.readline
def popcount(x):
    x -= (x >> 1) & 0x55555555
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x += x >> 8
    x += x >> 16
    return x & 0x3f
def popcount_parity(x):
    x ^= x >> 1
    x ^= x >> 2
    x ^= x >> 4
    x ^= x >> 8
    x ^= x >> 16
    return x & 1
n = int(input())
INF = 1 << 31
dist = [INF] * (n + 1)
dist[1] = 1
go = deque([1])
while go:
    now = go.pop()
    p = popcount(now)
    if now - p > 0:
        if dist[now - p] == INF:
            dist[now - p] = dist[now] + 1
            go.appendleft(now-p)
    if now + p <= n:
        if dist[now + p] == INF:
            dist[now + p] = dist[now] + 1
            go.appendleft(now+p)
if dist[n] == INF:
    print(-1)
else:
    print(dist[n])
0