Logo
(追記) (追記ここまで)

35039번 - Alphabet City 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 2048 MB121212100.000%

문제

Al is an urban designer in Alphabet City, and today their task is to prepare signs for $n$ 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 $m$ 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 $s_1, \ldots, 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 $k$ such that it is possible, from all the letters of $m$ copies of $s_1, \ldots, s_{\ell - 1}, s_{\ell + 1}, \ldots, s_n,ドル to compose $k$ copies of $s_1, \ldots, s_{\ell - 1}, s_{\ell + 1}, \ldots, s_n$ and additionally at least one copy of $s_\ell,ドル or to determine that such a composition is impossible for any non-negative $k$.

Al still does not know which of the items was lost. Write a program that, given $m$ and all street names, for each $\ell \in \{1, 2, \ldots, n\}$ prints the maximum value of $k,ドル or $-1$ if such a composition is impossible.

입력

The first line consists of two integers $n$ and $m,ドル 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 (2ドル \le n \le 2 \cdot 10^5$; 1ドル \le m \le 5 \cdot 10^5$). Each of the next $n$ lines consists of one string $s_i$ --- the street name (1ドル \le \left|s_i\right| \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 5ドル \cdot 10^5$.

출력

Print $n$ integers, the $\ell$-th of them denoting the maximum integer $k$ such that the letters of $m \times s_1,ドル $\ldots,ドル $m \times s_{\ell - 1},ドル $m \times s_{\ell + 1},ドル $\ldots,ドル $m \times s_n$ (where $m \times s$ denotes $m$ copies of street name $s$) are enough to compose $k \times s_1,ドル $\ldots,ドル $k \times s_{\ell - 1},ドル 1ドル \times s_\ell,ドル $k \times s_{\ell + 1},ドル $\ldots,ドル $k \times s_n$. If, for the given value of $\ell,ドル these letters are insufficient for any integer $k \ge 0,ドル print $-1$ instead.

제한

예제 입력 1

3 10
NEERC
NERC
NEF

예제 출력 1

9 9 -1

예제 입력 2

4 4
LENSE
TEN
SENSELESSNESSES
LENSE

예제 출력 2

3 -1 0 3

노트

출처

ICPC > Regionals > Northern Eurasia > Northern Eurasia Finals > Northern Eurasia Finals 2025 A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /