刷刷水~

Code:

#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 200005
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
char str1[N],str2[N];
int tot,last,n,c[N<<1],rk[N<<1];
struct Node
{
int ch[26],f,len,cnt;
}t[N<<1];
void extend(int c,int flag)
{
int np=++tot,p=last;
last=np,t[np].len=t[p].len+1;
for(;p&&!t[p].ch[c];p=t[p].f) t[p].ch[c]=np;
if(!p) t[np].f=1;
else
{
int q=t[p].ch[c];
if(t[q].len==t[p].len+1) t[np].f=q;
else
{
int nq=++tot;
t[nq].len=t[p].len+1;
t[nq].f=t[q].f,t[q].f=t[np].f=nq;
memcpy(t[nq].ch,t[q].ch,sizeof(t[q].ch));
for(;p&&t[p].ch[c]==q;p=t[p].f) t[p].ch[c]=nq;
}
}
t[np].cnt=flag;
}
int main()
{
int i,j;
long long answer=0;
// setIO("input");
scanf("%d%s%s",&n,str1+1,str2+1);
for(last=tot=i=1;i<=n;++i) extend(str1[i]-'a',str2[i]=='0'?1:0);
for(i=1;i<=tot;++i) ++c[t[i].len];
for(i=1;i<=tot;++i) c[i]+=c[i-1];
for(i=1;i<=tot;++i) rk[c[t[i].len]--]=i;
for(i=tot;i>=1;--i)
{
int p,ff;
p=rk[i],ff=t[p].f;
answer=max(answer,(long long)t[p].len*t[p].cnt);
t[ff].cnt+=t[p].cnt;
}
printf("%lld\n",answer);
return 0;
}

  

CF873F Forbidden Indices 后缀自动机+水题的更多相关文章

  1. 【CF873F】Forbidden Indices 后缀自动机

    [CF873F]Forbidden Indices 题意:给你一个串s,其中一些位置是危险的.定义一个子串的出现次数为:它的所有出现位置中,不是危险位置的个数.求s的所有子串中,长度*出现次数的最大值 ...

  2. Match & Catch CodeForces - 427D 后缀自动机水题

    题意: 给出两个字符串a,b,求一个字符串,这个字符串是a和b的子串, 且只在a,b中出现一次,要求输出这个字符串的最小长度. 题解: 将a串放入后缀自动机中,然后记录一下每个节点对应的子串出现的次数 ...

  3. 牛客网 桂林电子科技大学第三届ACM程序设计竞赛 A.串串-后缀自动机模板题

    链接:https://ac.nowcoder.com/acm/contest/558/A来源:牛客网 A.串串 小猫在研究字符串. 小猫在研究字串. 给定一个长度为N的字符串S,问所有它的子串Sl…r ...

  4. BZOJ 5084: hashit 后缀自动机(原理题)

    比较考验对后缀自动机构建过程的理解. 之前看题解写的都是树链的并,但是想了想好像可以直接撤销,复杂度是线性的. 自己想出来的,感觉后缀自动机的题应该不太能难倒我~ 注意:一定要手画一下后缀自动机的构建 ...

  5. 【BZOJ5084】hashit(后缀自动机水过)

    点此看题面 大致题意: 每次在字符串后面加入或删除一个字符,求本质不同的子串个数. 后缀自动机 先说明,此题后缀自动机的确能过. 但我的后缀自动机比较弱,遇上一个较强的\(Hack\)数据就被卡掉了. ...

  6. SPOJ 1811 Longest Common Substring (后缀自动机第一题,求两个串的最长公共子串)

    题目大意: 给出两个长度小于等于25W的字符串,求它们的最长公共子串. 题目链接:http://www.spoj.com/problems/LCS/ 算法讨论: 二分+哈希, 后缀数组, 后缀自动机. ...

  7. spoj - Longest Common Substring(后缀自动机模板题)

    Longest Common Substring 题意 求两个串的最长公共子串. 分析 第一个串建后缀自动机,第二个串在自动机上跑,对于自动机上的结点(状态)而言,它所代表的最大长度为根结点到当前结点 ...

  8. POJ - 2774 Long Long Message (后缀数组/后缀自动机模板题)

    后缀数组: #include<cstdio> #include<algorithm> #include<cstring> #include<vector> ...

  9. poj2774(后缀数组水题)

    http://poj.org/problem?id=2774 题意:给你两串字符,要你找出在这两串字符中都出现过的最长子串......... 思路:先用个分隔符将两个字符串连接起来,再用后缀数组求出h ...

随机推荐

  1. [转帖]How does a CPU work?

    How does a CPU work? https://milapneupane.com.np/2019/07/06/how-does-a-cpu-work/ CPU, also known as ...

  2. 【经典问题】maximum subset sum of vectors

    AtCoder Beginner Contest 139 Task F Engines 题目大意 给定 $n$ 个二维向量,从中选出若干个,使得它们的和的模最大. 分析 这是一个经典问题,还有一种提法 ...

  3. JAVAEE 7 api.chm

    JAVAEE 7 api.chm 链接:https://pan.baidu.com/s/1LUD3oam5B-Hp8tdpfQYk2w 提取码:x1kc

  4. liunx忘记用户密码

    1.vim /etc/my.cnf [mysqld] skip-grant-tables ##追加此行,跳过权限表, 2.重启mysql systemctl restart mysqld 3.mysq ...

  5. redis 学习(4)-- 哈希类型

    redis 学习(4)-- 哈希类型 介绍 redis 中哈希键值结构: 可以看出:哈希键值包括 key,field,value 这三部分,即键,属性,值这三部分.可以这样来表示: key, (fie ...

  6. tomcat搭建webDav

    工具准备: tomcat-8.0.53 前言:由于工作需要,希望自己搭建webdav服务端,刚开始用windowsServer 2012 R2版本自带的IIS服务器搭建,搭建好之后浏览器可以访问,但无 ...

  7. 解决mac下brew install报错

    Error: Another active Homebrew update process is already in progress.Please wait for it to finish or ...

  8. 如何在Python中快速画图——使用Jupyter notebook的魔法函数(magic function)matplotlib inline

    如何在Python中快速画图--使用Jupyter notebook的魔法函数(magic function)matplotlib inline 先展示一段相关的代码: #we test the ac ...

  9. 解决postgresql数据库localhost可以连接,ip连接不了的问题

    解决:windows环境下,postgresql数据库,localhost可以连接,ip地址连接不了. 解决办法: 1.打开postgresql安装目录下的配置文件 pg_hba.conf       ...

  10. 51. N-Queens (JAVA)

    The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens ...