結果

問題 No.3 ビットすごろく
ユーザー siganaisiganai
提出日時 2022-05-26 14:33:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,022 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 81,500 KB
実行使用メモリ 63,368 KB
最終ジャッジ日時 2023-10-20 19:26:32
合計ジャッジ時間 4,327 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 57 ms
63,368 KB
testcase_03 AC 58 ms
63,368 KB
testcase_04 WA -
testcase_05 AC 58 ms
63,368 KB
testcase_06 AC 59 ms
63,368 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 57 ms
63,368 KB
testcase_13 AC 58 ms
63,368 KB
testcase_14 AC 57 ms
63,368 KB
testcase_15 AC 57 ms
63,368 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 57 ms
63,368 KB
testcase_23 AC 58 ms
63,368 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 57 ms
63,368 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env PyPy3

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