結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2019-06-25 13:39:59 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 36 ms / 5,000 ms |
コード長 | 640 bytes |
コンパイル時間 | 82 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-07-01 09:23:02 |
合計ジャッジ時間 | 2,102 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
def main(): goal = int(input()) def bin1(n): return bin(n).count("1") Q = [0] * (goal + 1) q = [1] Q[1] = 1 while q: position = q.pop(0) stepLength = bin1(position) stepCount = Q[position] go = position + stepLength back = position - stepLength if go < goal + 1 and Q[go] == 0: Q[go] = stepCount + 1 q.append(go) if back > 0 and Q[back] == 0: Q[back] = stepCount + 1 q.append(back) if Q[goal] != 0: print(Q[goal]) else: print(-1) if __name__ == "__main__": main()