結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
dn6049949
|
| 提出日時 | 2022-04-15 22:25:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 82 ms / 5,000 ms |
| コード長 | 914 bytes |
| コンパイル時間 | 391 ms |
| コンパイル使用メモリ | 82,324 KB |
| 実行使用メモリ | 69,376 KB |
| 最終ジャッジ日時 | 2024-12-25 01:15:20 |
| 合計ジャッジ時間 | 4,109 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def IR(n):
return [I() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def main():
def popcount(n):
return bin(n).count("1")
n = I()
d = [float("inf")]*(n+1)
d[1] = 1
q = deque([1])
while q:
x = q.popleft()
dx = popcount(x)
nd = d[x]+1
for nx in (x-dx,x+dx):
if 1 <= nx <= n and nd < d[nx]:
d[nx] = nd
q.append(nx)
ans = d[n]
if ans == float("inf"):
ans = -1
print(ans)
return
if __name__ == "__main__":
main()
dn6049949