CF1055D.Refactoring
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice has written a program and now tries to improve its readability. One of the ways to improve readability is to give sensible names to the variables, so now Alice wants to rename some variables in her program. In her IDE there is a command called "massive refactoring", which can replace names of many variable in just one run. To use it, Alice needs to select two strings s and t and after that for each variable the following algorithm is performed: if the variable's name contains s as a substring, then the first (and only first) occurrence of s is replaced with t. If the name doesn't contain s, then this variable's name stays the same.
The list of variables is known and for each variable both the initial name and the name Alice wants this variable change to are known. Moreover, for each variable the lengths of the initial name and the target name are equal (otherwise the alignment of the code could become broken). You need to perform renaming of all variables in exactly one run of the massive refactoring command or determine that it is impossible.
Alice 编写了一个程序,现在她希望提升该程序的可读性。提升可读性的方法之一是为变量赋予有意义的名称;因此,Alice 想要重命名程序中的一些变量。她的集成开发环境(IDE)中有一个名为“大规模重构”(massive refactoring)的命令,可在一次执行中批量替换多个变量的名称。要使用该命令,Alice 需要选定两个字符串 s 和 t,之后对每个变量执行如下算法:若该变量的名称包含 s 作为子串,则将其中第一次(且仅第一次)出现的 s 替换为 t;若该变量名称不包含 s,则其名称保持不变。
已知所有待处理变量的列表,且对每个变量,均已知其初始名称以及 Alice 希望将其更改为的目标名称。此外,对每个变量,其初始名称与目标名称的长度相等(否则代码的缩进或对齐可能被破坏)。你需要判断:是否能恰好通过一次“大规模重构”命令完成所有变量的重命名;若可以,请给出对应的 s 和 t;否则判定为不可能。
输入格式
The first line contains the only integer n (1≤n≤3000) — the number of variables in Alice's program.
The following n lines contain the initial names of variables w1,w2,…,wn, one per line. After that, n more lines go, the i-th of them contains the target name wi′ for the i-th variable. It is guaranteed that 1≤∣wi∣=∣wi′∣≤3000.
It is guaranteed that there is at least one variable having its target name different from the initial name. Both initial and target names consist of lowercase English letters only. For each variable the length of its initial name is equal to the length of its target name.
第一行包含唯一一个整数 n(1≤n≤3000)—— 表示爱丽丝程序中变量的个数。
接下来的 n 行每行包含一个变量的初始名称 w1,w2,…,wn。随后还有 n 行,其中第 i 行包含第 i 个变量的目标名称 wi′。保证对每个 i,有 1≤∣wi∣=∣wi′∣≤3000。
保证至少存在一个变量,其目标名称与初始名称不同。所有初始名称和目标名称均由小写英文字母组成。对每个变量,其初始名称的长度等于其目标名称的长度。
输出格式
If it is impossible to rename all variables with one call of "massive refactoring", print "NO" (quotes for clarity).
Otherwise, on the first line print "YES" (quotes for clarity) and on the following lines print s and t (1≤∣s∣,∣t∣≤5000), which should be used for replacement. Strings s and t should consist only of lowercase letters of English alphabet.
If there are multiple ways to perform a "massive refactoring", you can use any of them.
如果无法通过一次“大规模重构”操作重命名所有变量,请输出 "NO"(引号仅用于清晰显示)。
否则,在第一行输出 "YES"(引号仅用于清晰显示),并在接下来的行中输出 s 和 t(1≤∣s∣,∣t∣≤5000),它们将被用作替换字符串。字符串 s 和 t 必须仅由英文字母的小写字符组成。
如果存在多种方式执行“大规模重构”,任选其一即可。
输入输出样例
输入#1
1 topforces codecoder
输出#1
YES topforces codecoder
输入#2
3 bab cac cdc bdb cdc cdc
输出#2
YES a d
输入#3
2 you shal not pass
输出#3
NO
输入解题思路,AI测评打分。不知道怎么写?