結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
SidewaysOwl
|
| 提出日時 | 2021-10-12 21:40:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 60 ms / 5,000 ms |
| コード長 | 473 bytes |
| コンパイル時間 | 544 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 72,832 KB |
| 最終ジャッジ日時 | 2024-09-17 09:01:57 |
| 合計ジャッジ時間 | 3,100 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
n = int(input())
l = [[] for _ in range(n)]
for i in range(n):
bl = bin((i+1)).count("1")
a = (i+1) + bl
b = (i+1) - bl
if a <= n:
l[i].append(a-1)
if b >= 1:
l[i].append(b-1)
from collections import deque
q = deque([[0,1]])
vis = [-1] * n
vis[0] = 1
while q:
node,cnt = q.popleft()
# print(q,node,cnt)
for nd in l[node]:
if vis[nd] == -1:
vis[nd] = cnt + 1
q.append([nd,cnt+1])
print(vis[-1])
SidewaysOwl