結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
lllllll88938494
|
| 提出日時 | 2022-01-21 11:30:02 |
| 言語 | Python3 (3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 53 ms / 5,000 ms |
| + 766µs | |
| コード長 | 525 bytes |
| 記録 | |
| コンパイル時間 | 54 ms |
| コンパイル使用メモリ | 15,104 KB |
| 実行使用メモリ | 11,520 KB |
| 最終ジャッジ日時 | 2026-09-29 17:00:50 |
| 合計ジャッジ時間 | 2,980 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge4_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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