結果

問題 No.3 ビットすごろく
ユーザー tookunn_1213tookunn_1213
提出日時 2015-08-16 13:05:52
言語 Python2
(2.7.18)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 506 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 6,472 KB
実行使用メモリ 6,468 KB
最終ジャッジ日時 2023-09-13 23:19:02
合計ジャッジ時間 2,003 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,900 KB
testcase_01 AC 11 ms
5,900 KB
testcase_02 AC 11 ms
5,968 KB
testcase_03 AC 14 ms
5,956 KB
testcase_04 AC 11 ms
5,860 KB
testcase_05 AC 18 ms
6,024 KB
testcase_06 AC 15 ms
6,164 KB
testcase_07 AC 13 ms
5,948 KB
testcase_08 AC 17 ms
5,976 KB
testcase_09 AC 22 ms
6,164 KB
testcase_10 AC 23 ms
6,400 KB
testcase_11 AC 20 ms
6,100 KB
testcase_12 AC 19 ms
6,172 KB
testcase_13 AC 14 ms
5,924 KB
testcase_14 AC 23 ms
6,396 KB
testcase_15 AC 26 ms
6,468 KB
testcase_16 AC 25 ms
6,140 KB
testcase_17 AC 25 ms
6,276 KB
testcase_18 AC 13 ms
5,884 KB
testcase_19 AC 26 ms
6,260 KB
testcase_20 AC 12 ms
5,852 KB
testcase_21 AC 11 ms
6,104 KB
testcase_22 AC 23 ms
6,216 KB
testcase_23 AC 26 ms
6,260 KB
testcase_24 AC 26 ms
6,244 KB
testcase_25 AC 25 ms
6,288 KB
testcase_26 AC 11 ms
5,980 KB
testcase_27 AC 14 ms
5,916 KB
testcase_28 AC 25 ms
6,220 KB
testcase_29 AC 21 ms
6,032 KB
testcase_30 AC 10 ms
6,108 KB
testcase_31 AC 11 ms
5,904 KB
testcase_32 AC 19 ms
6,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(raw_input())
queue = [1,1]
path = [False for i in range(N)]
ans = -1
path[0] = True
while len(queue) > 0:
	now,count= queue.pop(0),queue.pop(0)
	if now == N:
		ans = count
		break
	s = str(bin(now)).count('1')
	if s == 0:continue
	next1 = now + s
	next2 = now - s
	if not(next1 > N or path[next1 - 1]):
		path[next1 - 1] = True
		queue.append(next1)
		queue.append(count + 1)
	if not(next2 <= 0 or path[next2 - 1]):
		path[next2 - 1] = True
		queue.append(next2)
		queue.append(count + 1)
print ans
0