#P4548. [CTSC2006] 歌唱王国
[CTSC2006] 歌唱王国
Description
In the Singing Kingdom, everyone’s name is a non-empty string consisting only of integers from .
There lives a large group of Gurubing soldiers in the kingdom. They gain power by continuously singing the names of the leaders—the “Niuren chieftains”. Each singing process works like this: first, a soldier gets a number from the integer generator, then spends one unit of time to sing this number. If he finds that the name of some Niuren chieftain has already been sung (that is, the name appears as a contiguous substring of the singing sequence), then this singing process ends immediately.
Definitions:
- Singing sequence: If someone has sung numbers, and the number sung at the -th step is , then the singing sequence .
- Integer generator: A divine object in the Singing Kingdom. It has a button; if you press it once, it returns a random integer from with equal probability.
- Singing time: The time spent in one singing process.
The singing time is random and unpredictable. However, its expected value is fixed. This expected value describes how long the singing time is on average, and can also be called the average singing time.
People in the kingdom love singing. They want the singing time to be as long as possible, so they decide to remove (dismiss) some Niuren chieftains to make the average singing time longer. But they cannot remove all Niuren chieftains; otherwise, each singing process would never stop, and they would not be able to gain power. Therefore, they decide to keep only one Niuren chieftain and remove all the others.
Your task is: given , the number of Niuren chieftains , and the name of each Niuren chieftain, for each , if only the -th Niuren chieftain is kept and all others are removed, output what the average singing time will be.
Hint: This number is a non-negative integer.
Output requirement: Because this number is too large, you only need to output its last digits. If it has fewer than digits, pad leading zeros (see the sample).
Input Format
The first line contains two integers . The following lines describe the names of the Niuren chieftains.
Line () has the following format: the first number is , the length of the -th Niuren chieftain’s name. After a space, there are numbers describing this name, with one space between each pair of adjacent integers.
Output Format
Output lines. The -th line contains an integer, meaning the last four digits of the maximum average singing time when keeping only the -th Niuren chieftain and removing all others.
2 2
1 1
3 1 2 1
0002
0010
Hint
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号