結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-10-02 08:18:14 |
| 言語 | Python3 (3.14.3 + numpy 2.4.2 + scipy 1.17.0) |
| 結果 |
AC
|
| 実行時間 | 109 ms / 5,000 ms |
| コード長 | 795 bytes |
| 記録 | |
| コンパイル時間 | 374 ms |
| コンパイル使用メモリ | 20,700 KB |
| 実行使用メモリ | 15,484 KB |
| 最終ジャッジ日時 | 2026-03-22 06:15:47 |
| 合計ジャッジ時間 | 4,813 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
from collections import deque
def bit_one_count(N):
def maker(num):
return sum([int(i) for i in list(bin(num)[2:])])
return [maker(i) for i in range(1, N+1)]
def bfs(res, goal, route):
Q = deque([])
res[0] = 1
goal -= 1
Q.append(0)
while Q:
pos = Q.popleft()
if pos == goal:
return res
for i in [route[pos], -route[pos]]:
next_pos = pos + i
if not 0 <= next_pos <= goal:
continue
if res[next_pos] == -1:
Q.append(next_pos)
res[next_pos] = res[pos] + 1
return [-1]
def main():
N = int(input())
res = [-1] * N
route = bit_one_count(N)
s = bfs(res, N, route)
print(s[-1])
if __name__ == '__main__':
main()