FavouriteDigits
SRM 546 · 2011-11-22 · by misof
Problem Statement
Tetka Rapotacka just heard a juicy rumor about one of her neighbors: poor Jachym has lost N kacky (their local monetary unit) on a slot machine yesterday. Tetka Rapotacka now plans to share this rumor with everyone, including Tetka Klepetacka. Tetka Rapotacka has two favourite digits: digit1 and digit2. She only likes numbers that contain at least count1 occurrences of digit1 and at least count2 occurrences of digit2. When gossiping, she only uses numbers she likes. So if she does not like the number N, she will increase it until she finds a number that she likes.
You are given the
Notes
- The constraints guarantee that the return value will always fit into a long.
Constraints
- N will be between 1 and 10^15 - 1, inclusive.
- digit1 will be between 0 and 9, inclusive.
- digit2 will be between 0 and 9, inclusive.
- digit1 and digit2 will not be equal.
- count1 will be at least 0.
- count2 will be at least 0.
- count1+count2 will be at most 15.
47 1 0 2 0 Returns: 47
As count1=0 and count2=0, Tetka Rapotacka likes all numbers.
47 5 0 9 1 Returns: 49
The number has to contain the digit 9. The next number that contains this digit is 49.
47 5 0 3 1 Returns: 53
47 2 1 0 2 Returns: 200
The correct return value may have more digits than N.
47 5 1 0 0 Returns: 50
Submissions are judged against all 208 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FavouriteDigits with a public method long long findNext(long long N, int digit1, int count1, int digit2, int count2) · 208 test cases · 2 s / 256 MB per case