Editorial for COCI '10 Contest 1 #3 Sretan
Submitting an official solution before solving the problem yourself is a bannable offence.
A naïve solution would iterate over positive integers and check their luck until the lucky integer is found. Such a solution is worth of points.
A better solution is possible if a pattern is noticed in lucky numbers.
Specifically, if we substitute the digit with , and with , the lucky numbers correspond to binary number notation, with an additional quirk that leading zeros are allowed.
A solution iteratively generating the first lucky numbers using this observation has a complexity of and is worth of points.
Another speedup can be made by observing the number of lucky numbers with a given length. There are lucky numbers with length (since each of positions can contain one of two digits).
Knowing this, we can determine the length of the required lucky number and the index of that number among all lucky numbers of length . Then, it is sufficient to output the number in binary with the appropriate number of leading zeros, substituting digits and with and , respectively.
Comments