Champernowne Substring
Time limit10sMemory limit2048 MB
Fill each ? in the pattern with a digit to minimize the index where it first appears in the Champernowne string, printed mod 998244353.
- Level
Hard8 of 10
- Topics
- Dynamic programming, String, Math, Implementation
- Solved
- No attempts yet
Problem
The Champernowne string is an infinite string formed by concatenating the base-10 representations of the positive integers in order. It begins 1234567891011121314.... It can be proven that any finite string of digits appears as a substring in the Champernowne string at least once.
You are given a string made of digits and question marks. Replace each question mark with a single digit from to . Find the smallest possible index at which the resulting string appears as a substring of the Champernowne string. Each question mark can be replaced with a different digit. The index can be large, so print it modulo .
Input
The first line contains a single integer , the number of test cases. Each of the next lines contains a string made of the digits to and question marks.
Output
For each test case, print one line with the smallest index modulo .