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. jQuery进行简单验证的正则表达式

    下面都是一些比较常用简单的验证,像那些特殊的复杂的情况这里不进行考虑 1.验证电话号码或者手机号码 ? 1 2 3 4 5 6 7 8 9 10 /**  * 验证电话号码(手机号码+电话号码)  * ...

  2. ckeditor上传图片的注意点

    1.要在 ckeditor的  config.js 文件中加上 CKEDITOR.editorConfig = function( config ) { config.filebrowserImage ...

  3. 使用EasyBCD 从硬盘安装 deepin2014.1

    EasyBCD config  code: title Install Deepin2014 root (hd0,1) kernel (hd0,1)/vmlinuz boot=casper iso-s ...

  4. mac下安装composer

    打开命令后 cd /usr/local/bin 然后执行 curl -sS https://getcomposer.org/installer | php 接下来 sudo mv composer.p ...

  5. Android LayoutInflater解析

    在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById(). 不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实 ...

  6. CevaEclipse - 常用设置

    1. 往工程里面添加在硬盘上已有的文件 File -> Import.. -> General -> File System From directory Browse... 勾选需 ...

  7. vultr vps注册和后台教程

    我用了一年多vultr vps,感觉相当满意.我算是vultr最早的一批用户了,当时他们充值多少赠送多少,吸引大批新用户搬家到vultr,给linode和digitalocean vps不少的市场压力 ...

  8. 使用solrj查询数据(java代码)

    实体类Student,添加Field注解 package com.cs.solr.entity; import org.apache.solr.client.solrj.beans.Field; pu ...

  9. jquery ui sortable 实现table,row的拖动。(Make Table Rows Sortable Using jQuery UI Sortable)

    // Return a helper with preserved width of cells var fixHelper = function(e, ui) { //console.log(ui) ...

  10. socket编程,简单多线程服务端测试程序

    socket编程,简单多线程服务端测试程序 前些天重温了MSDN关于socket编程的WSAStartup.WSACleanup.socket.closesocket.bind.listen.acce ...