結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2019-01-31 15:18:00 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 920 bytes |
コンパイル時間 | 214 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 80,768 KB |
最終ジャッジ日時 | 2024-11-15 18:57:06 |
合計ジャッジ時間 | 83,931 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 TLE * 12 |
ソースコード
bitcount = {2:1, 6:2, 14:3, 30:4, 62:5, 126:6, 254:7, 510:8, 1022:9, 2046:10, 4094:11, 8190:12, 16382:13, } def get_max_bitcount(n): for i in bitcount: if n <= i: return bitcount[i] def foo(N): def get_reachable(st): reachable = set([]) for l in st: for i in range(1, get_max_bitcount(l)+2): if i == bin(l-i).count('1'): if (l-i) >= 1: reachable.add(l-i) if i == bin(l+i).count('1'): if (l+i) <= N: reachable.add(l+i) return reachable def bar(st): nonlocal count count += 1 if not st: return -1 if 1 in st: return count return bar(get_reachable(st)) if N == 1: return 1 count = 1 return bar(get_reachable(set([N]))) print(foo(int(input())))