PONY10 - When Does The World End
There is a recently discovered ancient temple, and Daring Do is already exploring it. She's come across an old Artifact of Power, which just seems to be spouting meaningless numbers. "...82980644837721883829806448..."
Reading the inscription on the wall, it gives an explanation to the artifact:
WE HAVE TAPPED INTO THE UNIVERSAL LIFE FORCE.
WE HEAR THE CLOCK TICKING TOWARD THE END.
CAN YOU HEAR IT?
WHEN THE PROPHESIED NUMBERS ARE SAID THE FORETOLD NUMBER OF TIMES
IT ENDS.
Daring Do doesn't know the prophesied numbers or foretold count, so she moves on with exploring.
She gets more clues while exploring:
- The artifact began counting at the beginning of time, starting from 0 and going up 1 step at a time, saying each digit individually. So when it first began, it went "0123456789101112131415...". Each second, it says the next digit. This means at time t=0, it said "0", at time t=1, it said "1", etc.
- The universe will end not on the tick after the prophesied number is said for the final time, it ends on the tick that the prophesied number begins. For instance, if the prophesied numbers were "01", and the foretold number of times were "2", then the universe would end at time t = 11. See below for more examples.
- She's found different things which could be the prophesied numbers, or the foretold number of times, but she's not sure.
Please help her figure out the life time of the universe, if the given pair of a 'foretold count' and 'prophesied numbers' were the true ones. But, if you take too long, the world might end before you figure it out!
Input Description
The first line is an integer T, indicating the number of test cases to follow. The following T lines will contain 2 things: a number K, the foretold count, and a string composed of digits, TARGET.
Output Description
For each test case, please determine S, the number of seconds until the prophesied number would be said for the final time. For test case i, please output "Case #i: S" on an individual line.
Example
Input: 6 1 0 1 00 9 1 2 01 100 25 5555 178 Output: Case #1: 0 Case #2: 191 Case #3: 22 Case #4: 11 Case #5: 9018 Case #6: 5104196
Explanation of Case #3
The artifact starts "01234567891011121314151617..." We see that '1' occurs for the 9th time at time t = 22.
Limits
For one test file, T ~= 100000. For the other five files, T ~= 10000
Of the possibilities found by Daring Do, they all seem to follow this limit:
LEN(K) + LEN(TARGET) <= 17.
In other words, if TARGET = "1", then K could potentially be "9999999999999999", but no larger.
whereas if TARGET = "1234567890123456", then K could potentially be "9", but no larger.
hide comments
Alex Anderson:
2017-07-01 02:36:11
@Krueger
|
|
Krueger:
2017-06-23 03:43:27
I've read through the description a few times, but I still may be missing something. How is the case of overlap handled?
|
|
Alex Anderson:
2017-01-02 11:23:17
@Kaio
|
|
Alex Anderson:
2016-12-17 08:27:18
@Kaio
|
|
Kaio César Nascimento Peixoto:
2016-12-11 19:59:40
People do you have any other input cases we could test? My program pass in all the inputs in the exemplo but when I submit i get wrong answer in the running(6). I would like some edge test cases to test. if that matters I'm using python 3.4 Last edit: 2016-12-11 20:02:19 |
|
Alex Anderson:
2016-08-19 08:54:59
@People trying to solve this. Good luck. I take a look here every once in awhile to see new attempts. |
|
Alex Anderson:
2016-03-26 18:50:15
@ash_hacker
|
|
ash_hacker:
2016-03-22 18:13:26
Your examples are contradictory, or less explanation is provided.
|
|
Alex Anderson:
2016-02-01 09:32:21
long long should be sufficient, given the limits. There shouldn't be any unreachable solutions. Do you have an example input which wouldn't fit into long long? |
|
Antonio Roberto Paoli:
2016-01-20 01:34:45
@cricycle
|
Added by: | Alex Anderson |
Date: | 2015-10-25 |
Time limit: | 6s-26s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 GOSU JS-MONKEY |
Resource: | My own problem |