結果
問題 | No.3 ビットすごろく |
ユーザー |
![]() |
提出日時 | 2020-05-21 00:57:38 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 455 bytes |
コンパイル時間 | 125 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 58,940 KB |
最終ジャッジ日時 | 2024-10-01 23:49:00 |
合計ジャッジ時間 | 36,523 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | RE * 33 |
ソースコード
n=int(input()) 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))