結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-01 22:22:53 |
| 言語 | Python3 (3.14.3 + numpy 2.4.2 + scipy 1.17.0) |
| 結果 |
AC
|
| 実行時間 | 128 ms / 5,000 ms |
| コード長 | 557 bytes |
| 記録 | |
| コンパイル時間 | 695 ms |
| コンパイル使用メモリ | 20,696 KB |
| 実行使用メモリ | 15,488 KB |
| 最終ジャッジ日時 | 2026-03-22 06:10:58 |
| 合計ジャッジ時間 | 5,314 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
import queue
#移動するマス数を求める関数
def calcpop(num):
return bin(num).count("1")
N=int(input())
q=queue.Queue()
q.put(1)
masu =[]
masu=[0]*10010
masu[1]=1
while q.empty()==False:
curpos=q.get()
popcnt=calcpop(curpos)
if (curpos-popcnt>0 and masu[curpos-popcnt]==0):
masu[curpos-popcnt]=masu[curpos]+1
q.put(curpos-popcnt)
if (curpos+popcnt<=N and masu[curpos+popcnt]==0):
masu[curpos+popcnt]=masu[curpos]+1
q.put(curpos+popcnt)
if masu[N]==0:
print(-1)
else:
print(masu[N])