CF2181A.Alphabet City

普及-

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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, \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 kk such that it is possible, from all the letters of mm copies of s1,…,sℓ−1,sℓ+1,…,sns_1, \ldots, s_{\ell - 1}, s_{\ell + 1}, \ldots, s_n, to compose kk copies of s1,…,sℓ−1,sℓ+1,…,sns_1, \ldots, s_{\ell - 1}, s_{\ell + 1}, \ldots, s_n and additionally at least one copy of sℓs_\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, \ldots, n} prints the maximum value of kk, or −1-1 if such a composition is impossible.

阿尔是字母城的一名城市规划师,今天他的任务是为该城市的 nn 条街道制作路牌。在字母城,路牌仅由街道名称构成,且每个字母均使用完全相同的、大写的英文字母金属印章冲压而成。例如,若有人在夜间偷偷将“NERC 街”和“NEF 街”的路牌首字母互换,则第二天无人能察觉差异,因为两个路牌上的字母 'N' 完全相同。

阿尔计划在每条街道上安装 mm 个路牌,并已向冶金工厂订购了每条街道名称所需数量的黄铜字母。然而,在订单送达前一小时,阿尔接到工厂经理打来的电话,告知了一个灾难性的消息:他们丢失了街道名称清单中的某一项!为缓解这一问题,阿尔决定:对未丢失订单的街道,尽可能多地安装路牌;并利用剩余的字母,至少为那条订单丢失的街道制作一个路牌。

形式化地,设 s1,…,sns_1, \ldots, s_n 为各街道名称,ℓ\ell 为订单中丢失项的下标(即 sℓs_\ell 对应的订单丢失),阿尔希望找出最大的整数 kk,使得:利用所有未丢失订单的街道名称(即 s1,…,sℓ−1,sℓ+1,…,sns_1, \ldots, s_{\ell - 1}, s_{\ell + 1}, \ldots, s_n)各自 mm 份所含的全部字母,能够拼出 kk 份这些未丢失街道的名称(即 kk 份 s1,…,sℓ−1,sℓ+1,…,sns_1, \ldots, s_{\ell - 1}, s_{\ell + 1}, \ldots, s_n),并且额外至少拼出一份丢失街道的名称 sℓs_\ell;或者判定:对任意非负整数 kk,这样的拼组均不可能实现。

目前阿尔尚不清楚哪一项订单丢失了。请编写一个程序:给定 mm 和全部街道名称,对每个 ℓ∈{1,2,…,n}\ell \in \{1, 2, \ldots, n\},输出对应的最大 kk 值;若这样的拼组对任意非负整数 kk 均不可能实现,则输出 −1-1。

输入格式

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 (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5; 1≤m≤5⋅1051 \le m \le 5 \cdot 10^5). Each of the next nn lines consists of one string sis_i — the street name (1≤∣si∣≤5⋅1051 \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⋅1055 \cdot 10^5.

第一行包含两个整数 nn 和 mm,分别表示 Alphabet 城需要路牌的街道数量,以及 Al 最初订购的每条街道名称的副本数量(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5;1≤m≤5⋅1051 \le m \le 5 \cdot 10^5)。接下来的 nn 行中,每行包含一个字符串 sis_i —— 街道名称(1≤∣si∣≤5⋅1051 \le \left|s_i\right| \le 5 \cdot 10^5)。所有这些名称均由大写英文字母组成。其中部分或全部名称可能相同。保证所有街道名称长度之和不超过 5⋅1055 \cdot 10^5。

输出格式

Print nn integers, the ℓ\ell-th of them denoting the maximum integer kk such that the letters of m×s1m \times s_1, ..., m×sℓ−1m \times s_{\ell - 1}, m×sℓ+1m \times s_{\ell + 1}, ..., m×snm \times s_n (where m×sm \times s denotes mm copies of street name ss) are enough to compose k×s1k \times s_1, ..., k×sℓ−1k \times s_{\ell - 1}, 1×sℓ1 \times s_\ell, k×sℓ+1k \times s_{\ell + 1}, ..., k×snk \times s_n. If, for the given value of ℓ\ell, these letters are insufficient for any integer k≥0k \ge 0, print −1-1 instead.

输出 nn 个整数,其中第 ℓ\ell 个整数表示最大的整数 kk,使得字符串 m×s1,…,m×sℓ−1,m×sℓ+1,…,m×snm \times s_1, \dots, m \times s_{\ell - 1}, m \times s_{\ell + 1}, \dots, m \times s_n(其中 m×sm \times s 表示将街道名 ss 重复 mm 次所构成的字符串)中所有字母,足以拼出 k×s1,…,k×sℓ−1,1×sℓ,k×sℓ+1,…,k×snk \times s_1, \dots, k \times s_{\ell - 1}, 1 \times s_\ell, k \times s_{\ell + 1}, \dots, k \times s_n。若对给定的 ℓ\ell,这些字母不足以拼出任意满足 k≥0k \ge 0 的整数 kk,则输出 −1-1。

输入输出样例

  • 输入#1

    3 10
    NEERC
    NERC
    NEF

    输出#1

    9 9 -1
  • 输入#2

    4 4
    LENSE
    TEN
    SENSELESSNESSES
    LENSE

    输出#2

    3 -1 0 3

输入解题思路,AI测评打分。不知道怎么写?

首页