A10593 | Delete Them
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are $n$ files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '\*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
- matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
- does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Polycarp faced the following problem. There are $n$ files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '\*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
- matches filenames "aabaa", "abba.", "a.ba9" and "a.ba.";
- does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
输入格式
The first line of the input contains two integers $n$ and $m$ ( $1<=m<=n<=100$ ) — the total number of files and the number of files to be deleted.
The following $n$ lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains $m$ distinct integer numbers in ascending order $a_{1},a_{2},...,a_{m}$ ( $1<=a_{i}<=n$ ) — indices of files to be deleted. All files are indexed from $1$ to $n$ in order of their appearance in the input.
The following $n$ lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains $m$ distinct integer numbers in ascending order $a_{1},a_{2},...,a_{m}$ ( $1<=a_{i}<=n$ ) — indices of files to be deleted. All files are indexed from $1$ to $n$ in order of their appearance in the input.
输出格式
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
If the required pattern doesn't exist, print the only line containing "No".
输入输出样例
输入 #1
3 2 ab ac cd 1 2
输出 #1
Yes a?
输入 #2
5 3 test tezt test. .est tes. 1 4 5
输出 #2
Yes ?es?
输入 #3
4 4 a b c dd 1 2 3 4
输出 #3
No
输入 #4
6 3 .svn .git .... ... .. . 1 2 3
输出 #4
Yes .???
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted