Page 2 of 2
next_permutation
Posted: Mon Sep 11, 2006 11:28 pm
by kalinov
fh wrote:the first thing i did was next_permutation(), but TLE
I got accepted in 5 sec by writing my own next_permutation procedure that calculates new remainder on the fly.
Also you can precalculate mod[x] = x mod d; up to 1000000 or so, to get rid of expensive mod operation.
Posted: Tue Sep 12, 2006 4:26 pm
by Vexorian
Hey thanks, I got rid of mod but by using substraction (in my algorithm is safe to just substract d from the new modulo if it is greater than or equal to d instead of just using mod) I saved 0.2 seconds, it still doubles the first place's time though.
Posted: Sat Sep 16, 2006 10:15 am
by mukeshtiwari
hi everybody , can any one explain the algorithm of this problem with a example......
thnkx......
Posted: Sun Oct 01, 2006 3:25 pm
by Vexorian
Now that the input changed it seems a lot of the people who used to have AC got Runtime Errror, including me.
Posted: Sat Oct 07, 2006 7:01 pm
by sclo
The change is that d is now 10000 as promised by the problem statement instead of 1000, so my code get RE. So I'm basically forced to change the way I memorize values.