結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2020-03-29 09:09:33 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 558 bytes |
コンパイル時間 | 249 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2025-01-02 13:10:44 |
合計ジャッジ時間 | 2,883 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 19 |
ソースコード
import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) inf=float("inf") Dist=[inf]*(n+1) def popcount(x): x=x-((x>>1)&0x5555555555555555) x=(x&0x3333333333333333)+((x>>2)&0x3333333333333333) x=(x+(x>>4))&0x0f0f0f0f0f0f0f0f x=x+(x>>8) x=x+(x>>16) x=x+(x>>32) return x&0x0000007f S=[1] Dist[1]=1 while S: s=S.pop() ss=popcount(s) if s+ss<=n and Dist[s+ss]==inf: Dist[s+ss]=Dist[s]+1 S.append(s+ss) if s-ss>=1 and Dist[s-ss]==inf: S.append(s-ss) Dist[s-ss]=Dist[s]+1 print(-1 if Dist[n]==inf else Dist[n])