結果

問題 No.3 ビットすごろく
ユーザー AAAR SalmonAAAR Salmon
提出日時 2021-01-16 00:52:21
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 640 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 10,972 KB
実行使用メモリ 9,240 KB
最終ジャッジ日時 2023-09-14 01:56:23
合計ジャッジ時間 2,305 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,784 KB
testcase_01 AC 21 ms
8,788 KB
testcase_02 AC 21 ms
8,756 KB
testcase_03 AC 24 ms
8,792 KB
testcase_04 AC 21 ms
8,752 KB
testcase_05 AC 28 ms
8,912 KB
testcase_06 AC 24 ms
8,948 KB
testcase_07 AC 23 ms
8,816 KB
testcase_08 AC 27 ms
8,944 KB
testcase_09 AC 30 ms
9,040 KB
testcase_10 AC 31 ms
8,992 KB
testcase_11 AC 30 ms
9,012 KB
testcase_12 AC 28 ms
8,936 KB
testcase_13 AC 23 ms
8,764 KB
testcase_14 AC 30 ms
9,020 KB
testcase_15 AC 34 ms
9,100 KB
testcase_16 AC 33 ms
9,144 KB
testcase_17 AC 33 ms
9,076 KB
testcase_18 AC 23 ms
8,916 KB
testcase_19 AC 34 ms
9,088 KB
testcase_20 AC 21 ms
8,756 KB
testcase_21 AC 21 ms
8,936 KB
testcase_22 AC 31 ms
9,032 KB
testcase_23 AC 34 ms
9,088 KB
testcase_24 AC 34 ms
9,128 KB
testcase_25 AC 34 ms
9,240 KB
testcase_26 AC 21 ms
8,888 KB
testcase_27 AC 24 ms
8,912 KB
testcase_28 AC 32 ms
9,128 KB
testcase_29 AC 29 ms
8,960 KB
testcase_30 AC 22 ms
8,840 KB
testcase_31 AC 22 ms
8,800 KB
testcase_32 AC 28 ms
8,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
from math import sin, cos, tan
from functools import reduce
from collections import deque
import heapq
sys.setrecursionlimit(1000000)
intm1 = lambda x:int(x)-1

def popcount(x):
	assert(0 <= x <= 0xFFFFFFFF)
	x = x - (x >> 1 & 0x55555555)
	x = (x & 0x33333333) + (x >> 2 & 0x33333333)
	x = (x + (x >> 4)) & 0x0f0f0f0f
	x = (x + (x >> 8)) & 0x00ff00ff
	x = (x + (x >> 16)) & 0x0000ffff
	return x 

N = int(input())
dp = [-1] * (N + 1)
dp[1] = 1
q = deque([1])
while q:
	c = q.popleft()
	d = popcount(c)
	for mv in [d, -d]:
		if 1 <= c+mv <= N and dp[c+mv] == -1:
			dp[c+mv] = dp[c] + 1
			q.append(c+mv)
print(dp[N])
0