結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2019-06-25 09:58:08 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 636 bytes |
コンパイル時間 | 107 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-06-22 23:35:40 |
合計ジャッジ時間 | 1,788 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
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) elif 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()