用第一个串建立后缀自动机。然后别的串在上面跑。从根节点开始。如果当前不能转移,一直移到slink或者根。如果移到根,能匹配长度变为0,否则变为maxlen[能转移的点]+1,再转移。转移完往slink上跑,它们至少都能匹配maxlen,和当前匹配取最小。注意在任何点上匹配长度不超过它能表示的最大长度。

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#include <fstream>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF,mod=;
int cnt,trans[SZ][],slink[SZ],maxlen[SZ];
int minlen[SZ],n,arr[SZ],ans[SZ];
//sadcsadsadasdasdsadsadasdasdsadasd
//aabba int add(int pre,int cur)
{
int z=++cnt;
int u=pre;
for(;u!=-&&!trans[u][cur];u=slink[u])
{
trans[u][cur]=z;
}
if(u==-)
{
//cout<<"kind: "<<1<<endl;
maxlen[z]=maxlen[pre]+;
minlen[z]=;
slink[z]=;
}
else
{
int x=trans[u][cur];
//if(pre==8)cout<<pre<<"here"<<x<<endl;
if(maxlen[x]==maxlen[u]+)
{
maxlen[z]=maxlen[pre]+;
minlen[z]=maxlen[x]+;
slink[z]=x;
}
else
{
int y=++cnt;
memcpy(trans[y],trans[x],sizeof(trans[x]));
maxlen[y]=maxlen[u]+;
minlen[y]=maxlen[slink[x]]+;
slink[y]=slink[x];
maxlen[x]=maxlen[x];
minlen[x]=maxlen[y]+;
slink[x]=y;
maxlen[z]=maxlen[pre]+;
minlen[z]=maxlen[y]+;
slink[z]=y;
for(;u!=-&&trans[u][cur]==x;u=slink[u])
{
trans[u][cur]=y;
}
}
}
return z;
} int maxv[SZ],tmp[SZ];
bool vst[SZ]; void init()
{
cin>>n;
for(int i=;i<n;++i)
{
int sz;
cin>>sz;
for(int i=;i<=sz;++i)cin>>arr[i];
for(int i=sz;i>=;--i)arr[i]-=arr[i-]-;
if(i==)
{
int pre=;
memset(slink,-,sizeof(slink));
for(int i=;i<=sz;++i)
{
pre=add(pre,arr[i]);
}
for(int i=;i<=cnt;++i)maxv[i]=INF;
}
else
{
memset(vst,,sizeof(vst));
memset(tmp,,sizeof(tmp));
int u=,it=;
for(int i=;i<=sz;++i)
{
int cur=arr[i];
for(;u!=-&&trans[u][cur]==;u=slink[u]);
if(u==-)
{
u=;
it=;
}
else
{
it=min(it,maxlen[u]);
u=trans[u][cur];
++it;
tmp[u]=max(tmp[u],it);
if(!vst[u])++ans[u];
//cout<<"u: "<<u<<" "<<tmp[u]<<endl;
vst[u]=;
int w=slink[u];
for(;w!=-;w=slink[w])
{
if(!vst[w])++ans[w],vst[w]=;
tmp[w]=max(tmp[w],min(it,maxlen[w]));
}
}
}
for(int i=;i<=cnt;++i)
{
//cout<<"tmp[i]: "<<tmp[i]<<endl;
maxv[i]=min(maxv[i],tmp[i]);
}
}
}
int res=;
for(int i=;i<=cnt;++i)
{
//cout<<"i: "<<i<<" "<<ans[i]<<" "<<maxv[i]<<endl;
if(ans[i]==n-&&maxv[i]!=INF)
{
res=max(res,maxv[i]);
}
}
cout<<res+<<endl;
} void work()
{ } int main()
{
//std::ios::sync_with_stdio(0);
//freopen("d:\\1.txt","r",stdin);
lon casenum;
//cin>>casenum;
//cout<<casenum<<endl;
//for(lon time=1;time<=casenum;++time)
//for(lon time=1;cin>>n,n;++time)
{
init();
work();
}
return ;
}
/*
3
5 0 0 1 1 1
5 1 0 0 1 1
5 1 0 1 1 1 5
5 1 1 1 1 1
5 1 1 1 1 1
5 1 1 1 1 1
5 1 1 1 1 1
5 1 1 1 1 1 3
8 0 0 1 1 0 0 1 1
8 0 1 1 0 1 0 1 1
8 1 1 1 1 1 0 1 1 3
6 0 0 1 1 0 0
6 0 1 1 0 1 0
6 1 1 1 1 1 0 3
5 0 1 1 0 0
5 1 1 0 1 0
5 1 1 1 1 0 3
4 1 1 0 0
4 1 0 1 0
4 1 1 1 0 3
4 1 1 0 0
4 1 1 1 1
4 1 1 0 1
*/

「SDOI2008」Sandy 的卡片的更多相关文章

  1. LG2463/BZOJ4698 「SDOI2008」Sandy的卡片 后缀数组

    问题描述 LG2463 BZOJ4698 题解 看到\(n\)个数串,一开始不太好处理,可以很容易想到把这\(n\)个数串连到一起,形成一个大串,但是每个串之间不容易处理. 经过思考,想到在每个串中间 ...

  2. B【SDOI2008】Sandy的卡片

    时间限制 : 5000 MS   空间限制 : 128000 KB 问题描述 Sandy和Sue的热衷于收集干脆面中的卡片.然而,Sue收集卡片是因为卡片上漂亮的人物形象,而Sandy则是为了积攒卡片 ...

  3. 「SDOI2008」洞穴勘测

    题目链接 戳我 \(Solution\) \(LCT\)裸题 \(Connect\)操作,执行\(link(u,v)\) \(Destroy\)操作,执行\(cut(u,v)\) \(Query\)操 ...

  4. [SDOI2008][luogu2463] Sandy的卡片 [kmp]

    题面 传送门 思路 这道题里面有三个主要问题: 1.由"数值相等"变成了"加上一个整数以后数值相等"(减去等价于加负数) 2.由"最多匹配多少位(从第 ...

  5. BZOJ 4698: Sdoi2008 Sandy的卡片

    4698: Sdoi2008 Sandy的卡片 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 106  Solved: 40[Submit][Stat ...

  6. BZOJ 4698: Sdoi2008 Sandy的卡片 [后缀自动机]

    4698: Sdoi2008 Sandy的卡片 题意:差分后就是多个串LCS SAM+map大法好 模板打错 智力-2 #include <iostream> #include <c ...

  7. 洛谷 P2463 [SDOI2008]Sandy的卡片 解题报告

    P2463 [SDOI2008]Sandy的卡片 题意 给\(n(\le 1000)\)串,定义两个串相等为"长度相同,且一个串每个数加某个数与另一个串完全相同",求所有串的最长公 ...

  8. bzoj4698 / P2463 [SDOI2008]Sandy的卡片

    P2463 [SDOI2008]Sandy的卡片 直接二分长度暴力匹配....... 跑的还挺快 (正解是后缀数组的样子) #include<iostream> #include<c ...

  9. 【BZOJ4698】Sdoi2008 Sandy的卡片 后缀数组+RMQ

    [BZOJ4698]Sdoi2008 Sandy的卡片 Description Sandy和Sue的热衷于收集干脆面中的卡片.然而,Sue收集卡片是因为卡片上漂亮的人物形象,而Sandy则是为了积攒卡 ...

随机推荐

  1. 分块读取Blob字段数据(Oracle)

    试过了MSSQL的分块读取Blob字段,又尝试在Oracle下完成,发现还是可行的. 首先建立一个存储过程: create or replace procedure PRO_GET_BLOB(     ...

  2. Bootstrap3基础 container 浏览器宽度与容器宽度的四种配合

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  3. 如何使用jqueryUi的datepicker日历控件?

    参考: http://www.jb51.net/article/85007.htm 这里的日历控件是, 基于jquery的jqureyui中的一个 widget. 需要js 文件: 外部的js文件, ...

  4. bzoj2086: [Poi2010]Blocks DP,单调栈

    题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2086 思路 这就有点妙了 题目意思就是让你求平均数>=k的最长序列 先求出a[i] ...

  5. Sql Ado.net 学习笔记之连接字符串

    https://www.cnblogs.com/heng95/p/5902019.html 连接字符串 SQL Client .net数据提供程序在连接到数据库时极其灵活,它提供了多种用以生成连接字符 ...

  6. (转载)用C#实现MySQL建库及建表

    最近做一个项目,为了方便用户使用,希望可以在系统初始化的时候,自动实现MySQL数据库的建库和建表操作.在网上查了很多资料都没有找到合适的,偶尔在一个国外网站上看到了相关的内容,特把实现方法整理如下: ...

  7. 使用Python制作第一个爬虫程序

    用到的开发环境 IDE:pycharm python  version :2.7 掌握的知识:  Pycharm  还能更改Python的版本 代码如下:(重点就是   正则表达式的学习) # !/u ...

  8. Ubuntu 14.04 安装 boost 1_57_0

    参考: How to build boost 1_57_0 Ubuntu platform Ubuntu 14.04 安装 boost 1_57_0 $ sudo mkdir /opt/downloa ...

  9. 2、corosync集群初步

    配置高可用集群 配置环境:两台centos7 192.168.184.141  192.168.184.142 corosync v2 + pacemaker corosync v2:vote sys ...

  10. 2、iptables基本应用

    iptables:规则管理工具 添加.修改.删除.显示等: 规则和链有计数器: pkts:  由规则或链所匹配到的报文的个数: bytes:由规则或链匹配到的所有报文大小之和: iptables命令: ...