H. Delete Them
time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

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.

Input

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 a1, a2, ..., am (1 ≤ ai ≤ n) — indices of files to be deleted. All files are indexed from 1 to n in order of their appearance in the input.

Output

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".

Examples
Input
3 2
ab
ac
cd
1 2
Output
Yes
a?
Input
5 3
test
tezt
test.
.est
tes.
1 4 5
Output
Yes
?es?
Input
4 4
a
b
c
dd
1 2 3 4
Output
No
Input
6 3
.svn
.git
....
...
..
.
1 2 3
Output
Yes
.???
/*
有一个坑,就是全是?的情况:虽然想删除的没有一个能匹配的,但是只要长度和其他的不一样就行了
*/
#include<bits/stdc++.h>
#define N 110
using namespace std;
char str[N][N];
int op[N];
int visit[N];
int visit2[N];
vector<string> v1,v2;
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
int n,m;
memset(visit,,sizeof visit);
memset(visit2,,sizeof visit2);
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%s",&str[i]);
for(int i=;i<=m;i++)
{
scanf("%d",&op[i]);
visit2[op[i]]=;
}
int flag=;
for(int i=;i<m;i++)
{
if(strlen(str[op[i]])!=strlen(str[op[i+]]))
flag=;
//cout<<strlen(str[op[i]])<<" "<<strlen(str[op[i+1]])<<endl;
}
if(!flag)
{
puts("No");
return ;
}
//cout<<"ok"<<endl;
int len=strlen(str[op[]]);
int cur=;
for(int i=;i<len;i++)
{
int f=;
for(int j=;j<m;j++)
{
if(str[op[j]][i]!=str[op[j+]][i])
{
f=;
break;
}
//cout<<str[op[j]][i]<<""<<str[op[j+1]][i]<<endl;
}
if(f)
{
//cout<<"ok"<<endl;
visit[i]=;
cur++;
}
}
if(!cur)
{
int F=;
for(int i=;i<=n;i++)
{
if(strlen(str[i])==strlen(str[op[]])&&!visit2[i])
{
F++;
}
}
if(!F)
{
puts("Yes");
for(int i=;i<len;i++)
printf("?");
printf("\n");
}
else
puts("No");
return ;
}
else
{
for(int i=;i<=n;i++)
{
if(strlen(str[i])==len&&!visit2[i])
{
int cur1=;
for(int j=;j<len;j++)
{
if(visit[j]&&str[i][j]==str[op[]][j])
{
//cout<<i<<endl;
cur1++;
}
}
if(cur1==cur)
{
//cout<<"ok"<<endl;
puts("No");
return ;
}
}
}
puts("Yes");
for(int i=;i<len;i++)
{
if(visit[i])
printf("%c",str[op[]][i]);
else
printf("?");
}
printf("\n");
}
return ;
}

2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest H. Delete Them的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  4. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  5. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  6. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  7. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  8. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...

  9. 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

随机推荐

  1. Python 接口测试(四)

    五:python数列化和反序列化 把python的对象编码转换为json格式的字符串,反序列化可以理解为:把json格式 字符串解码为python数据对象.在python的标准库中,专门提供了json ...

  2. 再说AutoComplete

    一.简述 昨天support一同事,帮她的客户做类似下面的效果(自动完成): 以前在搜房的时候,弄过这个,调用楼盘字典: 这是一个小功能,也是一个大功能.因为它可以做大,也可以做小. 二.搜房的Aut ...

  3. Java基础——集合源码解析 List List 接口

    今天我们来学习集合的第一大体系 List. List 是一个接口,定义了一组元素是有序的.可重复的集合. List 继承自 Collection,较之 Collection,List 还添加了以下操作 ...

  4. 基于NIO和BIO的两种服务器对比

    基于BIO的服务器,服务端可能要同时保持几百万个HTTP连接,而这些连接并不是每时每刻都在传输数据,所以这种情况不适合使用BIO的服务器:而且需要保证共享资源的同步与安全,这个实现起来相对复杂.这时候 ...

  5. Message:Unable to locate element 问题解决方法

    Python断断续续学了有一段时间了,总感觉不找个小项目练练手心里没底,哪成想出门就遇到"拦路虎",一个脚本刚写完就运行报错,还好做足了心里准备,尝试自行解决. 或许网上有相关解决 ...

  6. Tomcat的四种基于HTTP协议的Connector性能比较

    Tomcat从5.5版本开始,支持以下四种Connector的配置分别为: <Connector port="8081" protocol="org.apache. ...

  7. [Oracle]理解undo表空间

    一.回退段介绍 在Oracle数据库中,当某个事物对数据进行修改时,Oracle首先将数据的原始值保存到一个回退段中.一个事物只能将它的回退信息保存到一个回退段中,而多个并行事物可以使用同一个回退段. ...

  8. bzoj1027 [HNOI2004]打鼹鼠

    [HNOI2004]打鼹鼠 2014年5月2日2,8605 Description 鼹鼠是一种很喜欢挖洞的动物,但每过一定的时间,它还是喜欢把头探出到地面上来透透气的.根据这个特点阿Q编写了一个打鼹鼠 ...

  9. svn服务端安装、权限修改以及客户端的使用

    2017-10-1016:10:2 svn服务端安装.权限修改以及客户端的使用 svn服务端.客户端.汉化包下载 http://pan.baidu.com/s/1c1Ogj2C 1.安装服务器端程序( ...

  10. javascript小节

      javascript 语法总结 知识概要: (1)Javascript概述 1.1javascript是什么? 1.2JavaScript语言组成 1.3JavaScript与Html的结 ...