2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest H. Delete Them
2 seconds
512 megabytes
standard input
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.
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.
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".
3 2
ab
ac
cd
1 2
Yes
a?
5 3
test
tezt
test.
.est
tes.
1 4 5
Yes
?es?
4 4
a
b
c
dd
1 2 3 4
No
6 3
.svn
.git
....
...
..
.
1 2 3
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的更多相关文章
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 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 ...
- Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...
- codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解
秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...
- 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, ...
- 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)
i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...
- 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$ 思路: 定义一个二元组$< ...
- 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing
[链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...
随机推荐
- [js高手之路] 设计模式系列课程 - 迭代器(1)
迭代器是指通过一种形式依次遍历数组,对象,或者类数组结构中的每个元素. 常见的有jquery中的each方法, ES5自带的forEach方法. 下面我们就来自定义一个类似jquery或者ES5的迭代 ...
- pycharm 2017新建文件添加编码方式等
file->setting->Editor->File and Code Templates->Python Script 添加 #!/usr/bin/python3# -*- ...
- H5页面解决IOS进入不自动播放问题(微信内)
废话少说,直接上代码. 主要还是调用微信的jdk做兼容处理.,安卓可自动播放. ($(function(){ $(function(){ /* ** 复选框*/ $('.ul-radio').on(' ...
- 用ES6巧妙的解决传统面试中的算法小问题!
最近自己也在准备面试,在复习算法的时候,机智的用了一波ES6.一起来瞧瞧吧! 1.数组的去重 var arr=str.split(''); for(var i=0;i<arr.length-1; ...
- PHP浮点型(float)转换为整形(int)/round()保留小数点后几位
round(x,y); x:需要转换的变量 y:保留几位小数 <?php echo round(3.112312321) //输出3 echo round(3.112312321,3) //输出 ...
- DOM中的parentNode总结
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- php Socket通信
<?php error_reporting(0); $host = "0.0.0.0"; $port = 1082; $maxUser = 10; set_time_limi ...
- 22.Linux-块设备驱动之框架详细分析(详解)
本节目的: 通过分析块设备驱动的框架,知道如何来写驱动 1.之前我们学的都是字符设备驱动,先来回忆一下 字符设备驱动: 当我们的应用层读写(read()/write())字符设备驱动时,是按字节/字符 ...
- gitlab与jenkins的自动化部署(通过webhook与ansilble)
gitlab与jenkins的自动化部署(通过webhook与ansilble) 1.部署介绍 gitlab服务器:192.168.1.49:80jenkins服务器:192.168.1.49:818 ...
- XML读取信息并显示
这个类命名叫Message.cs namespace Common { public class Message { /// <summary> /// 信息编号 /// </sum ...