Games on a CD
time limit per test

4 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

Several years ago Tolya had n computer games and at some point of time he decided to burn them to CD. After that he wrote down the names of the games one after another in a circle on the CD in clockwise order. The names were distinct, the length of each name was equal to k. The names didn't overlap.

Thus, there is a cyclic string of length n·k written on the CD.

Several years have passed and now Tolya can't remember which games he burned to his CD. He knows that there were g popular games that days. All of the games he burned were among these g games, and no game was burned more than once.

You have to restore any valid list of games Tolya could burn to the CD several years ago.

Input

The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 105) — the amount of games Tolya burned to the CD, and the length of each of the names.

The second line of the input contains one string consisting of lowercase English letters — the string Tolya wrote on the CD, split in arbitrary place. The length of the string is n·k. It is guaranteed that the length is not greater than 106.

The third line of the input contains one positive integer g (n ≤ g ≤ 105) — the amount of popular games that could be written on the CD. It is guaranteed that the total length of names of all popular games is not greater than 2·106.

Each of the next g lines contains a single string — the name of some popular game. Each name consists of lowercase English letters and has length k. It is guaranteed that the names are distinct.

Output

If there is no answer, print "NO" (without quotes).

Otherwise, print two lines. In the first line print "YES" (without quotes). In the second line, print n integers — the games which names were written on the CD. You should print games in the order they could have been written on the CD, it means, in clockwise order. You can print games starting from any position. Remember, that no game was burned to the CD more than once. If there are several possible answers, print any of them.

Examples
input
3 1
abc
4
b
a
c
d
output
YES
2 1 3
input
4 2
aabbccdd
4
dd
ab
bc
cd
output
NO
分析:字典树上的匹配,因为最多有k个容器;
   把匹配好的编号分别放入相应的容器里,最后看是否满足n个即可;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<ll,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=1e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,sz,cur_v;
struct node
{
int nxt[],id,num,pre,link;
}trie[maxn**];
char a[maxn*],b[maxn];
set<int>p[maxn];
void insert(int x)
{
int now=;
for(int i=;i<k;i++)
{
int y=b[i]-'a';
if(!trie[now].nxt[y]){
trie[now].nxt[y]=++sz;
trie[sz].pre=now;
trie[sz].num=y;
}
now=trie[now].nxt[y];
}
trie[now].id=x;
}
int link(int v);
int go(int v, int c) {
if (trie[v].nxt[c]) {
return trie[v].nxt[c];
}
if (v == ) {
return ;
}
return trie[v].nxt[c] = go(link(v), c);
} int link(int v) {
if (trie[v].link) {
return trie[v].link;
}
if (v == || trie[v].pre == ) {
return ;
}
return trie[v].link = go(link(trie[v].pre), trie[v].num);
}
void check(int x)
{
cur_v=go(cur_v,a[x]-'a');
if(trie[cur_v].id)
{
p[(x-k+)%k].insert(cur_v);
}
}
int get_id(int x)
{
int now=;
for(int i=;i<k;i++)
{
int y=a[i+x]-'a';
now=trie[now].nxt[y];
}
return trie[now].id;
}
int main()
{
int i,j;
scanf("%d%d%s",&n,&k,a);
for(i=;i<k;i++)a[i+n*k]=a[i];
scanf("%d",&m);
rep(i,,m)
{
scanf("%s",b);
insert(i);
}
for(i=;i<n*k+k;i++)
{
check(i);
}
for(i=;i<k;i++)
{
if(p[i].size()==n)
{
puts("YES");
for(j=i;j<n*k+i;j+=k)printf("%d ",get_id(j));
return ;
}
}
puts("NO");
//system("Pause");
return ;
}

Games on a CD的更多相关文章

  1. CodeForces - 727E Games on a CD 字符串Hash

    题意:有n个单词,每个单词长度为k,顺时针将它们写成一个圆圈串.现在知道g个长度为k的单词,是否可以从这g个单词中选择n个形成这个圆圈串?如果有多个答案,任意输出一个. 思路 可以发现,如果枚举第一个 ...

  2. codeforces727E. Games on a CD

    题意:给一个n*k的循环字符串可能从任意地方断开,然后m个长度k的字符串,问你能不能用下面的字符串(每个最多用一次)构成上面的字符串,能循环移位 题解:对下面的串建ac自动机,记录字符串最后一个位置, ...

  3. 【CodeForces727E/CF727E】Games on a CD (字符串哈希)

    题目: CodeForces727E 分析: 看到字符串比较,肯定想到哈希啊--现学的哈希,先丢两个重要的公式 (\(seed\)是大于字符集大小的质数,\(p\)是大质数) \[hash[i]=(h ...

  4. Linux系统1.md

    计算机 介绍 电子计算机(英语:computer),亦称电脑,是一种利用电子学原理,根据一系列指令对数据进行处理的工具. 在现代,机械计算机的应用已经完全被电子计算机所替换,其所相关的技术研究叫计算机 ...

  5. 【Linux探索之旅】第二部分第三课:文件和目录,组织不会亏待你

    内容简介 1.第二部分第三课:文件和目录,组织不会亏待你 2.第二部分第四课预告:文件操纵,鼓掌之中 文件和目录,组织不会亏待你 上一次课我们讲了命令行,这将成为伴随我们接下来整个Linux课程的一个 ...

  6. 什么是shell? bash和shell有什么关系?

    什么是shell? bash和shell有什么关系? 博客分类: Linux   什么是Shell?      shell是你(用户)和Linux(或者更准确的说,是你和Linux内核)之间的接口程序 ...

  7. bash 基础命令

    bash的基础特性(): () 命令历史 history 环境变量: HISTSIZE:命令历史记录的条数: HISTFILE:~/.bash_history: HISTFILESIZE:命令历史文件 ...

  8. 什么是shell? bash和shell有什么关系?

    什么是Shell?      shell是你(用户)和Linux(或者更准确的说,是你和Linux内核)之间的接口程序.你在提示符下输入的每个命令都由shell先解释然后传给Linux内核.      ...

  9. 【Linux探索之旅】第二部分第三课:文件和文件夹,组织不会亏待你

    wx_fmt=jpeg" alt="" style="max-width:100%; height:auto!important"> 内容简单介 ...

随机推荐

  1. Spring Security(02)——关于登录

    目录 1.1     form-login元素介绍 1.1.1    使用自定义登录页面 1.1.2    指定登录后的页面 1.1.3    指定登录失败后的页面 1.2     http-basi ...

  2. mac 上面安装mysql-python

    安装过程中一直报错: EnvironmentError: mysql_config not found 最终下面的方式解决: 58down voteaccepted +200 Ok, well, fi ...

  3. openwrt 路由器变砖后修复方法

    https://wiki.openwrt.org/doc/howto/generic.debrick 变砖后需根据类型进行修复,主要有以下四种: (1)if only something on the ...

  4. hdu 2425 Hiking Trip (bfs+优先队列)

    Problem Description Hiking in the mountains is seldom an easy task for most people, as it is extreme ...

  5. MFC HTTP

    CInternetSession m_winet(NULL,,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,); CHttpConnection *pConnection; ...

  6. Sharepoint 的定制 - 代码附加内容编辑器

    //来源:http://www.cnblogs.com/codingcow/articles/69143.html Sharepoint是一种非常新而且很有用的技术. 现在微软把基本的功能集成到了Wi ...

  7. iOS 面试大全从简单到复杂(简单篇)

    1.UIWindow和UIView和 CALayer 的联系和区别? 答:UIView是视图的基类,UIViewController是视图控制器的基类,UIResponder是表示一个可以在屏幕上响应 ...

  8. Linux下gcc编译生成动态链接库*.so文件并调用它【转载】

    动态库*.so在linux下用c和c++编程时经常会碰到,最近在网站找了几篇文章介绍动态库的编译和链接,总算搞懂了这个之前一直不太了解得东东,这里做个笔记,也为其它正为动态库链接库而苦恼的兄弟们提供一 ...

  9. python初识1

    作者:武沛齐 出处:http://www.cnblogs.com/wupeiqi/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接. 安装Pyt ...

  10. flume+kafka+storm单机部署

    flume-1.6.0 kafka0.9.0.0 storm0.9.6 一.部署flume 1.解压 tar -xzvf apache-flume-1.6.0-bin.tar.gz -C ../app ...