結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
Valkyrja
|
| 提出日時 | 2020-05-21 00:59:02 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 488 bytes |
| コンパイル時間 | 164 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 59,324 KB |
| 最終ジャッジ日時 | 2024-07-01 09:48:50 |
| 合計ジャッジ時間 | 35,264 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 RE * 32 |
ソースコード
n=int(input())
if n==1:
print(1)
exit()
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
l=[]
for i in range(1,1+n):
j=bin(i)[2:].count("1")
if i+j<=n:
l.append((i,i+j,1))
if i-j>0:
l.append((i,i-j,1))
edge=np.array(l,dtype=np.int64).T
graph=csr_matrix(((edge[2],edge[:2]-1)),(n,n))
ans=dijkstra(graph,directed=True,indices=0)
if ans[n-1]==np.float("inf"):
print(-1)
else:
print(int(ans[n-1]+1))
Valkyrja