結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2017-02-22 19:19:24 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 647 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-12-30 19:08:39 |
合計ジャッジ時間 | 2,572 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
from collections import deque N = int(input()) d = [-1] * N checked = [False] * N p = [None] * N nxts = deque([0]) checked[0] = True while nxts: pos = nxts.pop() if pos == 0: d[pos] = 1 else: d[pos] = d[p[pos]] + 1 if pos == N - 1: print(d[N - 1]) quit() step = bin(pos + 1).count('1') if pos - step >= 0 and not checked[pos - step]: nxts.append(pos - step) checked[pos - step] = True p[pos - step] = pos if pos + step < N and not checked[pos + step]: nxts.append(pos + step) checked[pos + step] = True p[pos + step] = pos print(-1)