結果

問題 No.3 ビットすごろく
ユーザー ytftytft
提出日時 2022-11-01 00:11:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 210 ms / 5,000 ms
コード長 424 bytes
コンパイル時間 412 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 83,348 KB
最終ジャッジ日時 2023-09-22 20:59:50
合計ジャッジ時間 8,192 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 169 ms
80,928 KB
testcase_01 AC 167 ms
80,800 KB
testcase_02 AC 165 ms
80,868 KB
testcase_03 AC 203 ms
83,128 KB
testcase_04 AC 184 ms
82,700 KB
testcase_05 AC 202 ms
83,056 KB
testcase_06 AC 196 ms
82,904 KB
testcase_07 AC 189 ms
83,004 KB
testcase_08 AC 197 ms
82,944 KB
testcase_09 AC 205 ms
82,872 KB
testcase_10 AC 206 ms
83,148 KB
testcase_11 AC 203 ms
82,828 KB
testcase_12 AC 199 ms
83,020 KB
testcase_13 AC 195 ms
83,244 KB
testcase_14 AC 205 ms
83,136 KB
testcase_15 AC 208 ms
83,080 KB
testcase_16 AC 204 ms
83,084 KB
testcase_17 AC 206 ms
83,088 KB
testcase_18 AC 192 ms
82,904 KB
testcase_19 AC 208 ms
83,112 KB
testcase_20 AC 173 ms
80,976 KB
testcase_21 AC 166 ms
80,868 KB
testcase_22 AC 204 ms
83,176 KB
testcase_23 AC 210 ms
83,204 KB
testcase_24 AC 204 ms
83,200 KB
testcase_25 AC 205 ms
82,916 KB
testcase_26 AC 162 ms
80,892 KB
testcase_27 AC 193 ms
82,888 KB
testcase_28 AC 203 ms
83,348 KB
testcase_29 AC 200 ms
83,088 KB
testcase_30 AC 166 ms
80,752 KB
testcase_31 AC 170 ms
80,848 KB
testcase_32 AC 202 ms
83,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,queue
input=lambda:sys.stdin.readline().rstrip()
def count(N):
	return bin(N).count('1')
def con(a):
	return [a+count(a+1),a-count(a+1)]
N=int(input())
dist=[float('inf') for i in range(N)]
dist[0]=1
q=queue.SimpleQueue()
q.put(0)
while not q.empty():
	temp=q.get()
	for i in con(temp):
		if 0<=i<N and dist[i]>dist[temp]+1:
			dist[i]=dist[temp]+1
			q.put(i)
print(dist[N-1] if dist[N-1]!=float('inf') else -1)
0