#P15297. [ROI 2012 Day 1] calendar 古代日历
[ROI 2012 Day 1] calendar 古代日历
Background
Translation source: loj #5458. 「ROI 2012 Day 1」Ancient Calendar.
Problem Description
As everyone knows, in 2012 humans showed great interest in ancient calendars. Especially interesting were those calendars that did not end in 2012. Archaeologists in Tatarstan made an amazing discovery in this area. They found a rectangular stone tablet in an ancient tomb. After decoding the preserved symbols, they recorded it as a table with rows, each containing decimal digits. However, the tablet could not be fully decoded because some digits had been worn away. The missing digits in the table are replaced by the symbol *.
The archaeologists believe that this tablet is an ancient calendar, where the digits represent the day number for consecutive days within a certain period. The first digit string is the number of the first day in that period, and each following one is larger than the previous by . According to this calendar, the end of the world does not exist: after the day number consisting of nines, the next day number is the one consisting of zeros.
You need to write a program to restore the missing digits so that, starting from the second row, each number is greater than the number in the previous row by , and output the number of the first day in the found calendar.
Input Format
The first line of the input file contains two natural numbers and $(1 \leq N \leq 100000, 1 \leq M \leq 100000, M \times N \leq 100000)$, representing the number of rows in the table and the length of each row.
The next lines each contain characters, consisting only of decimal digits to and the symbol *.
Output Format
The output file should contain one line consisting of digits, representing the number of the first day in the calendar. If there are multiple ways to restore it, you may output any one. It is guaranteed that at least one restoration exists.
1 2
23
23
3 3
1**
*1*
**1
109
2 3
9**
00*
999
3 4
****
*0**
01**
0098
Hint
The detailed additional constraints and scores for subtasks are shown in the table below.
| Subtask | Score | Additional Constraints | Notes |
|---|---|---|---|
| , , each column has at least one preserved digit | You must pass all test points in this subtask to get the score. | ||
, , at least one column contains only * |
Each test point is scored independently. | ||
| , , | You must pass all test points in this subtask to get the score. |
Translated by ChatGPT 5