11525 - Permutation
Moderator: Board moderators
11525 - Permutation
I am getting TLE.
My approach is simple. I am using n-times delete function to delete a value which is already used for print.
Is it right way ?
My approach is simple. I am using n-times delete function to delete a value which is already used for print.
Is it right way ?
Re: 11525 - Permutation
You can improve the algorithm further. You don't need to n iterations to find what to print.
Hint: skip the numbers in block
-pvncad
Hint: skip the numbers in block
-pvncad
Re: 11525 - Permutation
my code gives TLE.
EDIT : Thank you all for advice
Code: Select all
AC
EDIT : Thank you all for advice
Last edited by Ron on Wed Oct 15, 2008 3:28 am, edited 3 times in total.
Re: 11525 - Permutation
Hint: split the vectors into smaller ones so that you search and removal time reduces.
-
- Experienced poster
- Posts: 196
- Joined: Wed May 02, 2007 10:12 pm
- Location: Hungary, Pest county, Halasztelek
- Contact:
Re: 11525 - Permutation
More precisely it's possible to solve this problem by interval tree (this is also a binary tree) in O(N*log(N)) time and in O(N) memory.Leonid wrote:I used binary tree to solve the problem.
Re: 11525 - Permutation
Done both idea
Using binary tree and splitting to subarrays.
But didn't understand why subarray method is faster than the other? Was it good test for this idea or generally it holds. Anyway best method might use binary tree because it is safe and usefull afterward.
Using binary tree and splitting to subarrays.
But didn't understand why subarray method is faster than the other? Was it good test for this idea or generally it holds. Anyway best method might use binary tree because it is safe and usefull afterward.
Re: 11525 - Permutation
should i use BigNum in this problem, i think if n = k! it's a very very big number.
another question is if this problem should use BigNum, it seems O(klgk) is not fast enough in my solution .
i need some help.
another question is if this problem should use BigNum, it seems O(klgk) is not fast enough in my solution .
i need some help.
Re: 11525 - Permutation
There is no need to compute factorials. Just find the kth smallest number that is not used (k starts from 0...so-on).
People have suggested using interval/segment trees to solve this problem. I've used fenwick trees to solve it. It is possible to find the kth smallest number using binary search.
People have suggested using interval/segment trees to solve this problem. I've used fenwick trees to solve it. It is possible to find the kth smallest number using binary search.
Re: 11525 - Permutation
I don't understand why this problem can use interval tree to solve it?
Could anyone give me some hint, plz?
Could anyone give me some hint, plz?