一道AC自动机题····

一定要把一个节点没有的儿子接到它fai的儿子,否则会卡到n^2的·······

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<ctime>
#define maxn 1048580
#define maxl 10005
using namespace std;
typedef long long int64;
char ch,s[maxl];
int fuckwmj=;
int n,l,head,tail,list[maxn];
int64 len;
struct Map{
int n,ans,ind[maxn],tot,now[maxn],son[maxn<<],pre[maxn<<],dep[maxn];
void init(int idx){
n=idx,ans=tot=;
memset(ind,,sizeof(ind));
memset(now,,sizeof(now));
memset(dep,,sizeof(dep));
}
void put(int a,int b){pre[++tot]=now[a],now[a]=tot,son[tot]=b,ind[b]++;}
void solve(){
head=,tail=;
for (int i=;i<=n;i++) if (!ind[i]) list[++tail]=i,dep[i]=;
while (head<tail){
int u=list[++head];
for (int p=now[u],v=son[p];p;p=pre[p],v=son[p]){
ind[v]--,dep[v]=max(dep[v],dep[u]+);
if (!ind[v]) list[++tail]=v;
}
}
for (int i=;i<=n;i++) if (ind[i]){puts("Yes");return;}
for (int i=;i<=n;i++) ans=max(ans,dep[i]);
if (ans>=len) puts("Yes");
else puts("No");
}
}dag;
struct trie{
int idx,son[maxn][],fai[maxn];
bool ok[maxn],bo[maxn];
void clear(){
idx=;
memset(son,,sizeof(son));
memset(fai,,sizeof(fai));
memset(ok,,sizeof(ok));
memset(bo,,sizeof(bo));
}
void insert(){
int p=;
for (int i=,op=(s[i]=='T');i<=l;p=son[p][op],i++,op=(s[i]=='T'))
if (!son[p][op]) son[p][op]=++idx;
ok[p]=;
}
void get_fai(){
head=,tail=,list[]=,fai[]=-,bo[]=;
while (head<tail){
int u=list[++head];
for (int ch=,v=son[u][ch],t;ch<=;v=son[u][++ch])
if (v&&!bo[v]){
bo[v]=,list[++tail]=v;
for (t=fai[u];t>=&&!son[t][ch];t=fai[t]);
if (t>=) fai[v]=son[t][ch]; else fai[v]=;
if (!son[v][]) son[v][]=son[fai[v]][];
if (!son[v][]) son[v][]=son[fai[v]][];
ok[v]=ok[v]|ok[u]|ok[fai[v]];
}
}
dag.init(idx);
head=,tail=,list[]=,bo[]=;
memset(bo,,sizeof(bo));
while (head<tail){
int u=list[++head];
for (int ch=,v=son[u][ch];ch<=;v=son[u][++ch])
if (v&&!ok[v]){
dag.put(u,v);
if (!bo[v]) bo[v]=,list[++tail]=v;
}
}
}
}T;
void get(){
for (ch=getchar();ch!='A'&&ch!='T';ch=getchar());
for (l=;ch=='A'||ch=='T';s[++l]=ch,ch=getchar());
}
int main(){
while (cin>>n>>len){
T.clear();
for (int i=;i<=n;i++) get(),T.insert();
T.get_fai(),dag.solve();
}
return ;
}

省队集训day6 B的更多相关文章

  1. 省队集训day6 C

    Description 给定平面上的 N 个点, 其中有一些是红的, 其他是蓝的.现在让你找两条平行的直线, 使得在保证    不存在一个蓝色的点 被夹在两条平行线之间,不经过任何一个点, 不管是蓝色 ...

  2. 省队集训day6 A

    code: #include<cstdio> #include<iostream> #include<cmath> #include<cstring> ...

  3. 省队集训 Day6 序列

    [题目大意] 给出$n$个数的序列$a_1, a_2, ..., a_n$,有$m$次操作,为下面三种: $A~l~r~d$:区间$[l,r]$,全部加$d$. $M~l~r~d$:区间$[l,r]$ ...

  4. HN2018省队集训

    HN2018省队集训 Day1 今天的题目来自于雅礼的高二学长\(dy0607\). 压缩包下载 密码: 27n7 流水账 震惊!穿着该校校服竟然在四大名校畅通无阻?霸主地位已定? \(7:10\)从 ...

  5. JS省队集训记

    不知不觉省队集训已经结束,离noi也越来越近了呢 论考前实战训练的重要性,让我随便总结一下这几天的考试 Day 1 T1 唉,感觉跟xj测试很像啊?meet in middle,不过这种题不多测是什么 ...

  6. LOJ #6074. 「2017 山东一轮集训 Day6」子序列

    #6074. 「2017 山东一轮集训 Day6」子序列 链接 分析: 首先设f[i][j]为到第i个点,结尾字符是j的方案数,这个j一定是从i往前走,第一个出现的j,因为这个j可以代替掉前面所有j. ...

  7. [2018HN省队集训D9T1] circle

    [2018HN省队集训D9T1] circle 题意 给定一个 \(n\) 个点的竞赛图并在其中钦定了 \(k\) 个点, 数据保证删去钦定的 \(k\) 个点后这个图没有环. 问在不删去钦定的这 \ ...

  8. [2018HN省队集训D8T1] 杀毒软件

    [2018HN省队集训D8T1] 杀毒软件 题意 给定一个 \(m\) 个01串的字典以及一个长度为 \(n\) 的 01? 序列. 对这个序列进行 \(q\) 次操作, 修改某个位置的字符情况以及查 ...

  9. [2018HN省队集训D8T3] 水果拼盘

    [2018HN省队集训D8T3] 水果拼盘 题意 给定 \(n\) 个集合, 每个集合包含 \([1,m]\) 中的一些整数, 在这些集合中随机选取 \(k\) 个集合, 求这 \(k\) 个集合的并 ...

随机推荐

  1. 例6.1:学生选课系统设计(界面设计、类图、数据库ER图)

  2. 《ACM国际大学生程序设计竞赛题解I》——6.10

    Pku 1143: Description Christine and Matt are playing an exciting game they just invented: the Number ...

  3. 《Mathematical Olympiad——组合数学》——操作和游戏

    这篇文章,我们开始对奥数中有关操作和游戏的问题进行分析和讨论,其实在信息学竞赛中涉及到的一些博弈问题(分析必胜策略)的问题(例如巴什博弈.尼姆博弈),本质上来讲,就是组合数学当中的组合游戏,并不是真正 ...

  4. u盘启动openwrt

    opkg update opkg install kmod-usb-ohci kmod-usb2 kmod-fs-ext3 opkg install kmod-usb-storage reboot m ...

  5. selenium webdriver python 操作Chrome浏览器

    Step1: 下载chromedriver. 下载路径: http://chromedriver.storage.googleapis.com/index.html 选择一个合适的下载即可.我下载的是 ...

  6. VGO新闻 - VGO

    VGO新闻 - VGO VGO天津伊势丹店盛装揭幕 VGO天津伊势丹店盛装揭幕2013年9月7日,VGO(微高)全国首家实体店在天津伊势丹百货盛装开幕.现场,100多位商场领导及业内同仁共同出席了

  7. python-从redis数据库中读数据

    读string,list,set,sort_set,hash类型的数据 import redis class DataBase: def __init__(self, host, port): sel ...

  8. 用canvas把图片变成黑白相片

    <!--这里没有代码--> 原来是把灰度系数分别 乘以 每个像素点的三个像素色(R,G,B)的值,然后得到的三个值加起来,再把得到的值赋值进去给每个R ,G,B. 微软的MSDN上提到的是 ...

  9. AS3 读写 C++ 64位数字

    为框架添加了一套新的与C++通讯的数据协议,其中和C++的大爷们对于他们的64位数字(unsigned long long)读写的问题纠结了很久.真心觉得“学好C++走遍天下都不怕啊” AS里Numb ...

  10. OpenCV 编码样式指南

    OpenCV 编码样式指南   前言 本文档是对OpenCV中代码风格的简短说明,因为OpenCV的核心库(cv,cvaux)是用C和C++编写的,所以本文档仅对用C和C++代码的编写有效.   文件 ...