結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
lllllll88938494
|
| 提出日時 | 2022-01-21 11:30:02 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 94 ms / 5,000 ms |
| コード長 | 525 bytes |
| コンパイル時間 | 200 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2024-11-25 05:41:35 |
| 合計ジャッジ時間 | 3,116 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
import sys
sys.setrecursionlimit(10**6)
n=int(input())
ns=[]
for i in range(n):
ns.append(bin(i+1).count('1'))
inf=10**7
dist=[inf]*n
ans=[10**10]
def dfs(x,cnt):
dist[x] = cnt
if x == n-1:
ans[0] = min(ans[0],cnt)
return
if x+ns[x] < n:
if dist[x+ns[x]] > cnt+1:
dfs(x+ns[x],cnt+1)
if x-ns[x] >= 0:
if dist[x-ns[x]] > cnt+1:
dfs(x-ns[x],cnt+1)
dfs(0,0)
if ans[0] == 10**10:
print(-1)
else:
print(ans[0]+1)
lllllll88938494