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. 如何理解CSS中的浮动 :其实他就像乘坐扶梯一样

    只要你用过自动扶梯,你就能很快的理解CSS中的浮动(Float). 你肯定遇到过这样的情况:       做好了,你想用CSS浮动来调整元素间的位置关系. 在写完代码之后,你发现浮动元素没出现在你设想 ...

  2. [SOJ] 1282. Computer games (KMP)

    坑爹题 1282. Computer Game Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Brian is an ...

  3. Linux添加软件连接方法

    这是linux中一个非常重要命令,请大家一定要熟悉.它的功能是为某一个文件或目录在另外一个位置建立一个同步的链接,类似Windows下的超级链接. 这个命令最常用的参数是-s,具体用法是:sudo l ...

  4. layoutSubview触发时机

    layoutSubviews在以下情况下会被调用: 1.init初始化不会触发layoutSubviews 2.addSubview会触发layoutSubviews 3.设置view的Frame会触 ...

  5. python-连接数据库

    from sqlalchemy import create_engine,text,Column,Integer,String,Sequencefrom sqlalchemy.ext.declarat ...

  6. Ubuntu14.04下手动建立快捷方式

    先在桌面创建一个文件:文件内容如下 [Desktop Entry]Encoding=UTF-8Name=eclipseComment=eclipse ideExec=/home/mars/eclips ...

  7. PHP CURL 代理发送数据

    $session = curl_init($request); curl_setopt ($session, CURLOPT_PROXY, $proxy); curl_setopt ($session ...

  8. 【Machine Learning in Action --4】朴素贝叶斯分类

    1.概述 朴素贝叶斯分类是贝叶斯分类器的一种,贝叶斯分类算法是统计学的一种分类方法,利用概率统计知识进行分类,其分类原理就是利用贝叶斯公式根据某对象的先验 概率计算出其后验概率(即该对象属于某一类的概 ...

  9. DPI与PPI

    首先应该明白几个概念: 1寸=3.3333333厘米(cm)1英寸(in)=2.54厘米(cm)屏幕尺寸: 屏幕对角线的长度.电脑电视同理.LCD是由液态晶体组成的显示屏(本向不发光) 有于电脑手机显 ...

  10. jail brak 获取当前安装app列表

    ios 5 6 7 可以通过解析"/private/var/mobile/Library/Caches/com.app.mobile.installation.plist" 文件获 ...