All submissions for this problem are available.
Chef likes numbers and number theory, we all know that. There are N digit strings that he particularly likes. He likes them so much that he defines some numbers to be beautiful numbers based on these digit strings.
Beautiful numbers are those numbers whose decimal representation contains at least one of chef's favorite digit strings as a substring.
Your task is to calculate the Kth smallest number amongst the beautiful numbers in the range from L to R (both inclusive).
If the number of beautiful numbers between L and R is less than K, then output "no such number".
In the first line of input there will be integers L, R, K and N.
Then N lines follow. Each line will contain a single string of decimal digits.
Output one integer - the solution to the problem described above or a string "no such number" if there is no such number.
- 1<=The length of any Chef's favourite digit string<=18. Each string begins with a nonzero digit.
Input: 1 1000000000 4 2 62 63 Output: 163
Input: 1 1 1 1 2 Output: no such number
Input: 1 1000 15 2 6 22 Output: 67
|Tags||aho-corasick, dynamic-programming, july12, medium, xcwgf666|
|Time Limit:||0.1 - 0.146779 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.