結果

問題 No.3 ビットすごろく
ユーザー Koharu Aoki 🌏🦊🇯🇵 青木小春Koharu Aoki 🌏🦊🇯🇵 青木小春
提出日時 2024-03-18 01:25:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 299 ms / 5,000 ms
コード長 433 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 94,668 KB
最終ジャッジ日時 2024-03-18 01:25:15
合計ジャッジ時間 7,255 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 117 ms
77,136 KB
testcase_04 AC 59 ms
72,656 KB
testcase_05 AC 179 ms
78,416 KB
testcase_06 AC 120 ms
77,264 KB
testcase_07 AC 75 ms
75,856 KB
testcase_08 AC 149 ms
77,772 KB
testcase_09 AC 196 ms
79,564 KB
testcase_10 AC 249 ms
82,380 KB
testcase_11 AC 193 ms
78,920 KB
testcase_12 AC 174 ms
78,408 KB
testcase_13 AC 113 ms
77,136 KB
testcase_14 AC 245 ms
82,252 KB
testcase_15 AC 288 ms
87,752 KB
testcase_16 AC 282 ms
83,400 KB
testcase_17 AC 281 ms
83,912 KB
testcase_18 AC 85 ms
75,984 KB
testcase_19 AC 289 ms
93,776 KB
testcase_20 AC 51 ms
67,872 KB
testcase_21 AC 35 ms
53,460 KB
testcase_22 AC 256 ms
82,248 KB
testcase_23 AC 287 ms
94,668 KB
testcase_24 AC 286 ms
94,288 KB
testcase_25 AC 277 ms
87,760 KB
testcase_26 AC 36 ms
53,460 KB
testcase_27 AC 112 ms
77,136 KB
testcase_28 AC 299 ms
83,408 KB
testcase_29 AC 188 ms
79,300 KB
testcase_30 AC 45 ms
61,716 KB
testcase_31 AC 46 ms
61,716 KB
testcase_32 AC 182 ms
78,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = [int(i) for i in input().split()][0]
count = 1 
check = set([1])
reach = set([1])
bitcount = lambda x : sum(int(i) for i in bin(x)[2:])
while N not in reach and len(check) > 0:
	left = set(i + bitcount(i) for i in check if i + bitcount(i) <= N)
	right = set(i - bitcount(i) for i in check if i - bitcount(i) > 0)
	reach, check = reach | check | left | right, (left | right) - reach
	count += 1
print(count if N in reach else -1)	
0