結果

問題 No.3 ビットすごろく
ユーザー mediocreRailmediocreRail
提出日時 2023-08-15 08:13:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,512 bytes
コンパイル時間 881 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 9,144 KB
最終ジャッジ日時 2023-08-15 08:13:08
合計ジャッジ時間 2,956 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,916 KB
testcase_01 AC 19 ms
9,000 KB
testcase_02 AC 19 ms
8,800 KB
testcase_03 AC 20 ms
8,936 KB
testcase_04 AC 20 ms
8,984 KB
testcase_05 AC 21 ms
9,000 KB
testcase_06 AC 22 ms
8,900 KB
testcase_07 AC 20 ms
8,864 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 20 ms
9,052 KB
testcase_13 AC 21 ms
8,960 KB
testcase_14 AC 22 ms
8,932 KB
testcase_15 AC 23 ms
8,968 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 21 ms
8,848 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 19 ms
8,880 KB
testcase_22 AC 21 ms
8,948 KB
testcase_23 AC 22 ms
9,140 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 20 ms
8,920 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 19 ms
8,972 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect,collections,itertools,math,functools,heapq
import sys
#sys.setrecursionlimit(10**6)
def I(): return int(sys.stdin.readline().rstrip())
def IN(): return int(input())
def LIN(): return list(map(int, input().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LF(): return list(map(float,sys.stdin.readline().rstrip().split()))
def SI(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

"""
方針
各門で引き返す or 通過するを足して計算する
"""

def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f

N=I()
dp = [-1]*(N+1)

stack = collections.deque()
stack.append(1)
dp[1] = 1
while stack:
    v = stack.popleft()
    p = popcount(v)
    if v+p <= N:
        if dp[v+p] >= 0: continue
        dp[v+p] = dp[v]+1
        stack.append(v+p)
    else:
        if dp[v-p] >= 0 or v-p < 0: continue
        dp[v-p] = dp[v] + 1
        stack.append(v-p)
    
print(dp[N])
0