#P14782. [NERC 2025] Alphabet City
[NERC 2025] Alphabet City
题目描述
Al is an urban designer in Alphabet City, and today their task is to prepare signs for city streets. In Alphabet City, the street signs simply consist of the street names composed of capital identically stamped English metal letters. For instance, if, during nighttime, someone sneakily exchanges the first letters on NERC street and on NEF street, the next day nobody will see the difference as the letter 'N' is identical on both signs.
Al is planning to put signs on each street, and they have already ordered the required number of brass letters for each of the street names from the metallurgical plant. However, one hour before the order arrived, Al got a call from the plant’s manager with a devastating piece of news: they lost one of the items from the list of street names! To mitigate the issue, Al decided for now to put as many signs as possible on each street whose order was not lost, and, with the leftover letters, to prepare at least one sign for the street whose order was lost.
Formally, if are the street names, and is the index of the missing item from the order, Al is interested in the maximum integer such that it is possible, from all the letters of copies of , to compose copies of and additionally at least one copy of , or to determine that such a composition is impossible for any non-negative . Al still does not know which of the items was lost. Write a program that, given and all street names, for each prints the maximum value of , or if such a composition is impossible.
输入格式
The first line consists of two integers and , denoting the number of streets in Alphabet City for which the signs are needed and the number of copies of each street name that Al initially ordered (; ). Each of the next lines consists of one string — the street name (). All these names are composed of capital English letters. Some or all of these names may coincide. It is guaranteed that the sum of the lengths of all the street names does not exceed .
输出格式
Print integers, the -th of them denoting the maximum integer such that the letters of $m \times s_1, \dots, m \times s_{\ell-1}, m \times s_{\ell+1}, \dots, m \times s_n$ (where denotes copies of street name ) are enough to compose $k \times s_1, \dots, k \times s_{\ell-1}, 1 \times s_\ell, k \times s_{\ell+1}, \dots, k \times s_n$. If, for the given value of , these letters are insufficient for any integer , print instead.
3 10
NEERC
NERC
NEF
9 9 -1
4 4
LENSE
TEN
SENSELESSNESSES
LENSE
3 -1 0 3