cf#579 D

http://codeforces.com/contest/1203/problem/D2
D2. Remove the Substring (hard version)
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
The only difference between easy and hard versions is the length of the string.

You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).

For example, the strings “test”, “tst”, “tt”, “et” and “” are subsequences of the string “test”. But the strings “tset”, “se”, “contest” are not subsequences of the string “test”.

You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.

If you want to remove the substring s[l;r] then the string s will be transformed to s1s2…sl−1sr+1sr+2…s|s|−1s|s| (where |s| is the length of s).

Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.

Input
The first line of the input contains one string s consisting of at least 1 and at most 2⋅105 lowercase Latin letters.

The first line of the input contains one string t consisting of at least 1 and at most 2⋅105 lowercase Latin letters.

It is guaranteed that t is a subsequence of s.

Output
Print one integer — the maximum possible length of the substring you can remove so that t is still a subsequence of s.

Examples
inputCopy
bbaba
bb
outputCopy
3
inputCopy
baaba
ab
outputCopy
2
inputCopy
abcde
abcde
outputCopy
0
inputCopy
asdfasdf
fasd
outputCopy
3
贪心,用两个数组记录子数组每个字符第一次和最后一次出现位置,ans就是firstpos[i]-lastpos[i+1]中最大的,fpos是关键字CE了三发。。。我太难了。。。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char t[200005],s[200005];
int lent,lens,fos[200005],lpos[200005];
int main()
{
	scanf("%s%s",s+1,t+1);
	lent=strlen(t+1),lens=strlen(s+1);
	int tmp=1;
	for(int i=1;i<=lent;i++)
	{
		while(s[tmp]!=t[i])
		tmp++;
		fos[i]=tmp;
		tmp++;
	}
	tmp=lens;
	for(int i=lent;i>0;i--)
	{
		while(s[tmp]!=t[i])
		tmp--;
		lpos[i]=tmp;
		tmp--;
	}
	int ans=0;
	ans=max(ans,lpos[1]-1);
	ans=max(ans,lens-fos[lent]);
	for(int i=1;i<lent;i++)
	ans=max(ans,lpos[i+1]-fos[i]-1);
	printf("%d\n",ans);
}
【事件触发一致性】研究多智能体网络如何通过分布式事件驱动控制实现有限时间内的共识(Matlab代码实现)内容概要:本文围绕多智能体网络中的事件触发一致性问题,研究如何通过分布式事件驱动控制实现有限时间内的共识,并提供了相应的Matlab代码实现方案。文中探讨了事件触发机制在降低通信负担、提升系统效率方面的优势,重点分析了多智能体系统在有限时间收敛的一致性控制策略,涉及系统模型构建、触发条件设计、稳定性与收敛性分析等核心技术环节。此外,文档还展示了该技术在航空航天、电力系统、机器人协同、无人机编队等多个前沿领域的潜在应用,体现了其跨学科的研究价值和工程实用性。; 适合人群:具备一定控制理论基础和Matlab编程能力的研究生、科研人员及从事自动化、智能系统、多智能体协同控制等相关领域的工程技术人员。; 使用场景及目标:①用于理解和实现多智能体系统在有限时间内达成一致的分布式控制方法;②为事件触发控制、分布式优化、协同控制等课题提供算法设计与仿真验证的技术参考;③支撑科研项目开发、学术论文复现及工程原型系统搭建; 阅读建议:建议结合文中提供的Matlab代码进行实践操作,重点关注事件触发条件的设计逻辑与系统收敛性证明之间的关系,同时可延伸至其他应用场景进行二次开发与性能优化。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值