Lakerka's blog

By Lakerka, 9 years ago, In English

I was trying to solve Timus 1032. Find a Multiple after several unsuccessful tries I made for fun submission with code and got AC now I am wondering why and how? My solution idea: if solution exists then we can arrange solution numbers to be prefix of rearranged sequence, since we don't know how to get those numbers just pick them randomly by shuffling sequence array if by change we get that those numbers form prefix we have solution. Repeat shuffling until we have solution or report that there is no solution if we are getting close to TLE.

I think that my solution should be incorrect because if we would have sequence with length n and there would be single unique solution of length k then the probability to guess right would be k! * (n - k)! / n!.

So I would like to ask if my solution is correct, if so why?

P.S. I know O(n), solution.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it