CF780D.Innokenty and a Football League

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters.

Each club's full name consist of two words: the team's name and the hometown's name, for example, "DINAMO BYTECITY". Innokenty doesn't want to assign strange short names, so he wants to choose such short names for each club that:

  1. the short name is the same as three first letters of the team's name, for example, for the mentioned club it is "DIN",
  2. or, the first two letters of the short name should be the same as the first two letters of the team's name, while the third letter is the same as the first letter in the hometown's name. For the mentioned club it is "DIB".

Apart from this, there is a rule that if for some club x the second option of short name is chosen, then there should be no club, for which the first option is chosen which is the same as the first option for the club x. For example, if the above mentioned club has short name "DIB", then no club for which the first option is chosen can have short name equal to "DIN". However, it is possible that some club have short name "DIN", where "DI" are the first two letters of the team's name, and "N" is the first letter of hometown's name. Of course, no two teams can have the same short name.

Help Innokenty to choose a short name for each of the teams. If this is impossible, report that. If there are multiple answer, any of them will suit Innokenty. If for some team the two options of short name are equal, then Innokenty will formally think that only one of these options is chosen.

因诺肯季是比特兰新足球联赛的主席。他首先要完成的任务是为所有俱乐部分配三个字母组成的简称,以便在电视转播比分时显示。当然,这些简称必须互不相同,且因诺肯季希望所有简称均由三个字母组成。

每个俱乐部的全名由两个单词组成:队名和所在城市名,例如“DINAMO BYTECITY”。因诺肯季不希望分配怪异的简称,因此他希望为每个俱乐部选择满足以下条件之一的简称:

  1. 简称等于队名的前三个字母,例如对上述俱乐部而言即为 “DIN”;
  2. 简称的前两个字母等于队名的前两个字母,而第三个字母等于所在城市名的首字母;对上述俱乐部而言即为 “DIB”。

此外还有一条规则:若对某个俱乐部 xx 选择了第二种简称方案,则不能存在任何其他俱乐部,其采用第一种方案所生成的简称恰好等于俱乐部 xx 采用第一种方案所生成的简称。例如,若上述俱乐部的简称选定为 “DIB”,则不允许有任何其他俱乐部采用第一种方案并得到简称 “DIN”。但允许存在某个俱乐部,其简称是 “DIN”,其中 “DI” 是该俱乐部队名的前两个字母,“N” 是其所在城市名的首字母。当然,任意两个俱乐部均不得拥有相同的简称。

请帮助因诺肯季为每支队伍分配一个简称。若无法完成分配,请报告此情况。若存在多种可行方案,任选其一即可。若对某支队伍而言,两种简称方案所得结果相同,则因诺肯季在形式上仅视作采用了其中一种方案。

输入格式

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of clubs in the league.

Each of the next n lines contains two words — the team's name and the hometown's name for some club. Both team's name and hometown's name consist of uppercase English letters and have length at least 3 and at most 20.

第一行包含一个整数 nn(1≤n≤10001 \leq n \leq 1000)—— 表示联赛中俱乐部的数量。

接下来的 nn 行,每行包含两个单词 —— 某个俱乐部的队名及其所在城市的名称。队名和城市名均由大写英文字母组成,且长度均在 33 到 2020 之间(含端点)。

输出格式

It it is not possible to choose short names and satisfy all constraints, print a single line "NO".

Otherwise, in the first line print "YES". Then print n lines, in each line print the chosen short name for the corresponding club. Print the clubs in the same order as they appeared in input.

If there are multiple answers, print any of them.

如果无法选择短名称并满足所有约束条件,则输出一行“NO”。

否则,第一行输出“YES”。然后输出 n 行,每行输出对应俱乐部所选的短名称。俱乐部的输出顺序应与输入中的顺序一致。

若存在多个可行解,输出任意一个即可。

输入输出样例

  • 输入#1

    2
    DINAMO BYTECITY
    FOOTBALL MOSCOW

    输出#1

    YES
    DIN
    FOO
  • 输入#2

    2
    DINAMO BYTECITY
    DINAMO BITECITY

    输出#2

    NO
  • 输入#3

    3
    PLAYFOOTBALL MOSCOW
    PLAYVOLLEYBALL SPB
    GOGO TECHNOCUP

    输出#3

    YES
    PLM
    PLS
    GOG
  • 输入#4

    3
    ABC DEF
    ABC EFG
    ABD OOO

    输出#4

    YES
    ABD
    ABE
    ABO

说明/提示

In the first sample Innokenty can choose first option for both clubs.

In the second example it is not possible to choose short names, because it is not possible that one club has first option, and the other has second option if the first options are equal for both clubs.

In the third example Innokenty can choose the second options for the first two clubs, and the first option for the third club.

In the fourth example note that it is possible that the chosen short name for some club x is the same as the first option of another club y if the first options of x and y are different.

在第一个样例中,伊诺肯季可以为两个俱乐部都选择第一种选项。

在第二个样例中,无法选择短名称,因为当两个俱乐部的第一种选项相同时,不可能出现一个俱乐部选第一种选项、而另一个俱乐部选第二种选项的情况。

在第三个样例中,伊诺肯季可以为前两个俱乐部选择第二种选项,为第三个俱乐部选择第一种选项。

在第四个样例中,请注意:对于某个俱乐部 xx 所选的短名称,有可能与另一个俱乐部 yy 的第一种选项相同,前提是俱乐部 xx 和 yy 的第一种选项互不相同。

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

首页