#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 nn 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 mm 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 s1,,sns_1, \dots, s_n are the street names, and \ell is the index of the missing item from the order, Al is interested in the maximum integer kk such that it is possible, from all the letters of mm copies of s1,,s1,s+1,,sns_1, \dots, s_{\ell-1}, s_{\ell+1}, \dots, s_n, to compose kk copies of s1,,s1,s+1,,sns_1, \dots, s_{\ell-1}, s_{\ell+1}, \dots, s_n and additionally at least one copy of ss_\ell, or to determine that such a composition is impossible for any non-negative kk. Al still does not know which of the items was lost. Write a program that, given mm and all street names, for each {1,2,,n}\ell \in \{1, 2, \dots, n\} prints the maximum value of kk, or 1-1 if such a composition is impossible.

输入格式

The first line consists of two integers nn and mm, 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 (2n21052 \le n \le 2 \cdot 10^5; 1m51051 \le m \le 5 \cdot 10^5). Each of the next nn lines consists of one string sis_i — the street name (1si51051 \le |s_i| \le 5 \cdot 10^5). 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 51055 \cdot 10^5.

输出格式

Print nn integers, the \ell-th of them denoting the maximum integer kk 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 m×sm \times s denotes mm copies of street name ss) 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 \ell, these letters are insufficient for any integer k0k \ge 0, print 1-1 instead.

3 10
NEERC
NERC
NEF
9 9 -1
4 4
LENSE
TEN
SENSELESSNESSES
LENSE
3 -1 0 3