結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
67oYG9nh2YMmIci
|
| 提出日時 | 2020-07-14 17:09:31 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,015 bytes |
| コンパイル時間 | 300 ms |
| コンパイル使用メモリ | 12,416 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2024-11-17 18:12:45 |
| 合計ジャッジ時間 | 2,620 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 RE * 2 |
ソースコード
import queue
N=int(input())
def calcpop(num):
return bin(num).count("1")
def bit():
q=queue.Queue()
q.put(1)
trout=[-1]*(N+10)
trout[1]=1
while q.empty()==False:
curpos=q.get() #現在のマス目
popcnt=calcpop(curpos) #現在のマス目を2進数に変換した時の1の数
if(trout[curpos-popcnt]==-1 and curpos-popcnt>0): #後ろのマスに移動するときの判定・処理
trout[curpos-popcnt]=trout[curpos]+1 #移動した先に移動数の最小値を記録
q.put(curpos-popcnt) #このマス目から次は探索を行うためキューに入れる
if(trout[curpos+popcnt]==-1 and curpos+popcnt<=N): #前のマスに移動する時の判定・処理
trout[curpos+popcnt] = trout[curpos] + 1 #移動した先に移動数の最小値を記録
q.put(curpos+popcnt) #このマス目から次は探索を行うためキューに入れる
print(trout[N])
if __name__ == "__main__":
bit()
67oYG9nh2YMmIci