結果

問題 No.3 ビットすごろく
ユーザー matriematrie
提出日時 2020-12-20 23:13:19
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
TLE  
実行時間 -
コード長 623 bytes
コンパイル時間 113 ms
コンパイル使用メモリ 12,028 KB
実行使用メモリ 53,536 KB
最終ジャッジ日時 2023-10-21 11:11:40
合計ジャッジ時間 9,396 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,256 KB
testcase_01 AC 30 ms
10,256 KB
testcase_02 AC 31 ms
10,256 KB
testcase_03 AC 1,616 ms
53,536 KB
testcase_04 AC 136 ms
13,880 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
a=int(input())
r=[[0]*a for _ in [0]*a]
for i in range(a):
	t=bin(i+1).count('1')
	if i+t<a: r[i][i+t]=1
	if i-t>0: r[i][i-t]=1

n=len(r)
u=list(range(n))
d=[math.inf]*n
pns=[-1]*n
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[n-1]
print(-1 if dis>a else dis+1)

'''
pn=num-1
while pn!=-1:
	if pn!=0:
		print(str(pn+1)+'<',end='')
	else: 
		print(str(pn+1))
	pn=pns[pn]
'''
0