結果

問題 No.3 ビットすごろく
ユーザー matriematrie
提出日時 2020-12-20 21:35:29
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
TLE  
実行時間 -
コード長 522 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 12,092 KB
実行使用メモリ 233,744 KB
最終ジャッジ日時 2023-10-21 11:04:16
合計ジャッジ時間 8,505 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,260 KB
testcase_01 AC 31 ms
10,260 KB
testcase_02 AC 30 ms
10,260 KB
testcase_03 AC 1,610 ms
53,540 KB
testcase_04 AC 137 ms
13,884 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
n=int(input())
r=[[0]*n for _ in [0]*n]
for i in range(n):
	t=bin(i+1).count('1')
	if i+t<n: r[i][i+t]=1
	if i-t>0: r[i][i-t]=1

num=len(r)
u=list(range(num))
d=[math.inf]*num
pns=[-1]*num
d[0]=0

def g(m,d,u):
	s=0
	while 1:
		i=d.index(m,s)
		if i in u: return i
		else: s=i+1

while(len(u)!=0):
	q=math.inf
	for ni in u:
		if q>d[ni]: q=d[ni]
	t=g(q,d,u) 
	u.remove(t)
	for i,rd in enumerate(r[t]):
		if rd!=0:
			if d[i]>(d[t]+rd):
				d[i]=d[t]+rd
				pns[i]=t

dis=d[num-1]
print(-1 if dis>n else dis+1)
0