Increasing Sequence
Time limit2sMemory limit128 MB
Split a huge digit string into pieces forming a strictly increasing sequence of numbers, breaking ties by minimizing the last piece then maximizing earlier pieces, and output the product mod 1,000,000,003.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, String, Math
- Solved
- No attempts yet
Problem
Jimin has one large integer with N digits.
He wants to insert spaces between digits and split it into several integers. The resulting integers must be strictly increasing from left to right. Equal values are not allowed, and an integer may start with 0.
If there is more than one valid split, choose one whose last integer is as small as possible. If there is still more than one, maximize the first integer; if still tied, maximize the second integer, and continue comparing from left to right.
Print the product of all integers in the chosen increasing sequence modulo 1,000,000,003.
Input
The first line contains one integer. Its length is at most 2500, and its first digit is not 0.
Output
Print the product of all elements in the chosen sequence modulo 1,000,000,003.
Hint
For the input 20210222, the following four splits minimize the last integer.
2 021 02222 0210 22220 21 022220 210 222
Comparing the first integer leaves the two splits that start with 20. Comparing the second integer then selects 20 210 222, because 210 is greater than 21.