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. ACM学习之路___HDU 2066 一个人的旅行

    Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还 ...

  2. JS设计模式(一) 单例模式

    命名空间 单例模式是JavaScript中最常见的一种模式,通过这种模式可以为我们提供一个命名空间,例如jQuery库的命名空间为jQuery或$.命名空间的使用是为了让代码更加整洁,在多人协作开发的 ...

  3. mint-ui vue双向绑定

    由于最近项目需求,用上了mint-ui来重构移动端页面,从框架本身来讲我觉得很强大了,用起来也很不错,但是文档就真的是,,,,让我无言以对,给的api对于我们这些小菜鸟来讲真的是处处是坑呀(ps:用v ...

  4. HDFS概述(5)————HDFS HA

    HA With QJM 目标 本指南概述了HDFS高可用性(HA)功能以及如何使用Quorum Journal Manager(QJM)功能配置和管理HA HDFS集群. 本文档假设读者对HDFS集群 ...

  5. localStorage和sessionStorage总结以及区别

    (1)兼容的手机和浏览器: (2)使用 .setItem( key, value)存键值数据 sessionStorage.setItem("key","value&qu ...

  6. CentOS 7搭建LAMP环境(二)

    前面已经讲过了CentOS 7下LAMP环境的配置过程,一台简单的WEB服务器已搭建完成,但后期在网站部署的过程中也许会碰到各种各样头疼的问题.下面我们来讲讲怎么解决这些问题,以及如何高效地管理服务器 ...

  7. C# 如何添加Word文本和图片超链接

    超链接简单来讲就是内容链接,通过设置超链接可以实现对象与网页.站点之间的连接.链接目标可以是网页.图片.邮件地址.文件夹或者是应用程序.设置链接的对象可以是文本或者图片. 在以下内容中,我将介绍如何用 ...

  8. java泛型使用总结

    1. 泛型方法: 2. 泛型类: 3. 通配符. 1.泛型方法 泛型方法在调用时可以接收不同类型的参数.根据传递给泛型方法的参数类型,编译器适当地处理每一个方法调用. 下面是定义泛型方法的规则: 所有 ...

  9. 如何获取url上面的参数

    例如 :网页.html?id=0 //获取url中"?"符后的字串 gofunction getRequest() { var url = window.location.sear ...

  10. 执行Sqlserver中waitfor delay延时操作或waitfor time定时操作

    private static string connectionString = RBAC.Dal.DataRootBase.ConnectionString; private SqlConnecti ...