Всем привет. Недавно я натолкнулся на задачу с UVA online judge.
Короткое условие: существует массив $$$a$$$ размера $$$n$$$. Вам заданы все попарные произведения элементов $$$a$$$ (всего $$$n \cdot (n-1)/2$$$) произведения). Вам нужно найти лексикографаически минимальный массив $$$a$$$. $$$n < 200$$$.
У кого-то есть идеи, как ее решить?
Auto comment: topic has been updated by unbelievable (previous revision, new revision, compare).
Gaussian elimination ?
Can you elaborate please?
If you know $$$a_1$$$ and $$$a_2$$$ you can restore the whole sequence. You can either try all divisor pairs of the smallest product or try to find $$$a_2 \cdot a_3$$$ pair and deduce $$$a_1, a_2$$$ using it ( https://cses.fi/problemset/task/2414/ )
Thanks. I got the idea. I guess I could implement it in
$$$O(divs(a_1) \ n ^2 \log n)$$$ (if I look for $$$a_1$$$ in divisors of first element)
or $$$O(n^4 \log n)$$$ (if I look for $$$a_1$$$ in all elements)
but both solutions does not seams good (There are 25 cases per test on UVa).
Am i missing something?
It's $$$\mathcal{O}(n^3 \log n)$$$ in the second case and most checks should fail early I believe.
Can this https://cses.fi/problemset/task/2414/ also be done in O(n^3 log n)?
I was able to solve it in O(n^4 log n)
Your solutions probably works in $$$\mathcal{O}(n^3 \log n)$$$. $$$a_2 + a_3$$$ must be in first $$$n$$$ terms.
Yes, I tried it and it worked. Thanks!!
Can you explain how you would do that?