結果

問題 No.3 ビットすごろく
ユーザー Koharu Aoki 🌏🦊🇯🇵 青木小春Koharu Aoki 🌏🦊🇯🇵 青木小春
提出日時 2024-03-18 01:26:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 300 ms / 5,000 ms
コード長 440 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 94,800 KB
最終ジャッジ日時 2024-03-18 01:27:06
合計ジャッジ時間 6,870 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 116 ms
77,008 KB
testcase_04 AC 57 ms
72,656 KB
testcase_05 AC 172 ms
77,776 KB
testcase_06 AC 116 ms
77,008 KB
testcase_07 AC 79 ms
75,856 KB
testcase_08 AC 153 ms
77,392 KB
testcase_09 AC 192 ms
78,800 KB
testcase_10 AC 242 ms
82,256 KB
testcase_11 AC 193 ms
78,288 KB
testcase_12 AC 166 ms
77,776 KB
testcase_13 AC 109 ms
77,008 KB
testcase_14 AC 242 ms
82,128 KB
testcase_15 AC 280 ms
88,016 KB
testcase_16 AC 282 ms
83,664 KB
testcase_17 AC 270 ms
84,176 KB
testcase_18 AC 82 ms
75,984 KB
testcase_19 AC 277 ms
94,032 KB
testcase_20 AC 57 ms
70,608 KB
testcase_21 AC 36 ms
53,460 KB
testcase_22 AC 254 ms
82,128 KB
testcase_23 AC 300 ms
94,800 KB
testcase_24 AC 281 ms
94,416 KB
testcase_25 AC 266 ms
88,016 KB
testcase_26 AC 35 ms
53,460 KB
testcase_27 AC 110 ms
77,008 KB
testcase_28 AC 269 ms
83,664 KB
testcase_29 AC 183 ms
78,416 KB
testcase_30 AC 43 ms
61,716 KB
testcase_31 AC 45 ms
61,716 KB
testcase_32 AC 176 ms
77,904 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, count = reach | check | left | right, (left | right) - reach, count + 1
print(count if N in reach else -1)	
0