「SDOI2008」Sandy 的卡片
用第一个串建立后缀自动机。然后别的串在上面跑。从根节点开始。如果当前不能转移,一直移到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 的卡片的更多相关文章
- LG2463/BZOJ4698 「SDOI2008」Sandy的卡片 后缀数组
问题描述 LG2463 BZOJ4698 题解 看到\(n\)个数串,一开始不太好处理,可以很容易想到把这\(n\)个数串连到一起,形成一个大串,但是每个串之间不容易处理. 经过思考,想到在每个串中间 ...
- B【SDOI2008】Sandy的卡片
时间限制 : 5000 MS 空间限制 : 128000 KB 问题描述 Sandy和Sue的热衷于收集干脆面中的卡片.然而,Sue收集卡片是因为卡片上漂亮的人物形象,而Sandy则是为了积攒卡片 ...
- 「SDOI2008」洞穴勘测
题目链接 戳我 \(Solution\) \(LCT\)裸题 \(Connect\)操作,执行\(link(u,v)\) \(Destroy\)操作,执行\(cut(u,v)\) \(Query\)操 ...
- [SDOI2008][luogu2463] Sandy的卡片 [kmp]
题面 传送门 思路 这道题里面有三个主要问题: 1.由"数值相等"变成了"加上一个整数以后数值相等"(减去等价于加负数) 2.由"最多匹配多少位(从第 ...
- BZOJ 4698: Sdoi2008 Sandy的卡片
4698: Sdoi2008 Sandy的卡片 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 106 Solved: 40[Submit][Stat ...
- BZOJ 4698: Sdoi2008 Sandy的卡片 [后缀自动机]
4698: Sdoi2008 Sandy的卡片 题意:差分后就是多个串LCS SAM+map大法好 模板打错 智力-2 #include <iostream> #include <c ...
- 洛谷 P2463 [SDOI2008]Sandy的卡片 解题报告
P2463 [SDOI2008]Sandy的卡片 题意 给\(n(\le 1000)\)串,定义两个串相等为"长度相同,且一个串每个数加某个数与另一个串完全相同",求所有串的最长公 ...
- bzoj4698 / P2463 [SDOI2008]Sandy的卡片
P2463 [SDOI2008]Sandy的卡片 直接二分长度暴力匹配....... 跑的还挺快 (正解是后缀数组的样子) #include<iostream> #include<c ...
- 【BZOJ4698】Sdoi2008 Sandy的卡片 后缀数组+RMQ
[BZOJ4698]Sdoi2008 Sandy的卡片 Description Sandy和Sue的热衷于收集干脆面中的卡片.然而,Sue收集卡片是因为卡片上漂亮的人物形象,而Sandy则是为了积攒卡 ...
随机推荐
- FileZilla建立服务器,命令行客户端
一.服务器 1.安装FileZilla 2.打开用户 3.输入用户名密码 4.选择目录 注意:files也可全部勾选上,以免没有权限上传 二.命令行作为客户端 1.进入ftp >>ftp ...
- Python3 tkinter基础 Label imag显示图片
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- P4246 [SHOI2008]堵塞的交通
思路 同LOJ121 动态图连通性的板子 好像有很神的线段树做法,不会,先码住 代码 #include <cstdio> #include <algorithm> #inclu ...
- [easyui] - 在easyui的table中展示提示框
因为在easyui的table中字段过多,而无法展示全时,被迫只能使用这个方法. 使用方式: 在 $('#dg').datagrid({ 后的 queryParams: form2Json('sear ...
- [implements] - 一个接口的使用
4种货物,如何使用一个接口实现CRUD: package com.tansuo365.test1.service.goods; import com.tansuo365.test1.entity.Go ...
- 【Mybatis】--配置SqlMapConfig文件中的几个注意事项
一.别名 如果设置别名后,就可以在Mapper.xml 文件中使用设置的别名 <typeAliases> <!-- 单个别名定义 --> <typeAlias alias ...
- facebook api之Ads Insights API
The Ads Insights API provides API access for reporting and analytics purposes. When exclusively usin ...
- SqlParameter 多个参数动态拼接解决参数化问题
多个参数化是固定比较easy,多个动态的就有点...工作中遇到的问题整理下来分享 ,上代码 SqlParameter[] param = new SqlParameter[] { }; List< ...
- RN中关于IOS和Android的相关权限的问题
在日常的开发中,时常需要去获取应用的一权限 比如查看通讯录/打开摄像机等 1:ios iOS 的权限管理在info.plist里设置 info.plist主要是管理了app 的一些信息文件,比如版本 ...
- 【BZOJ】3575: [Hnoi2014]道路堵塞
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3575 大概的做法是,按照顺序枚举每一条要删去的边,(假设当前点为$u$,在最短路径上的下一 ...