C. Two strings
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.

Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.

Input

The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters.

Output

On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.

If the answer consists of zero characters, output «-» (a minus sign).

Examples
input
hi
bob
output
-
input
abca
accepted
output
ac
input
abacaba
abcdcba
output
abcba
Note

In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.

In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.

题意:可以删除b字符串中的一个连续子串,需要你删除留下的最小字符;

思路:首先最开始的思路是n*n*log(n)的,TLE;

   枚举b的左端点,二分右端点,check需要O(n);

打表求出从1-i的字符串是a的子串的最小位置,同理求i-n的;

   可以优化成n*log(n);

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e5+,M=1e6+;
const ll INF=1e18+,mod=;
char a[N],b[N];
int l[N],r[N];
int n,m;
int main()
{
scanf("%s%s",a+,b+);
n=strlen(a+),m=strlen(b+);
int st=;
for(int i=;i<=m;i++)
{
while(st<=n&&a[st]!=b[i])st++;
r[i]=st;
if(st<=n)st++;
}
l[m+]=n+;
int en=n;
for(int i=m;i>=;i--)
{
while(en>=&&a[en]!=b[i])en--;
l[i]=en;
if(en>=)en--;
}
if(r[m]<=n) return *printf("%s\n",b+);
int ansl=,ansr=m;
for(int i=;i<=m;i++)
{
int st=i;
int en=m;
int ans=1e6;
while(st<=en)
{
int mid=(st+en)>>;
if(r[i-]<l[mid+])
{
en=mid-;
ans=mid;
}
else
st=mid+;
}
//cout<<ans<<" "<<i<<endl;
if(ans-i<ansr-ansl)
{
ansl=i;
ansr=ans;
}
}
if(ansl==&&ansr==m)
printf("-\n");
for(int i=;i<ansl;i++)
printf("%c",b[i]);
for(int i=ansr+;i<=m;i++)
printf("%c",b[i]);
printf("\n");
return ;
}

最新文章

  1. spring.net学习(一) 搭建环境,实例化spring.net容器。
  2. iOS中坐标转换
  3. [转]Ubuntu 16.04建议安装
  4. timeSeries db之:使用Metrics监控应用程序的性能 (zz)
  5. HTTP认证相关
  6. G面经prepare: Maximum Subsequence in Another String&#39;s Order
  7. RPC基础篇
  8. 【html5】这些新类型 能提高生产力
  9. ural 1123
  10. C中如何调用C++函数、类内函数 \混编\链接
  11. vbs系统监控
  12. DirectX11 With Windows SDK--24 Render-To-Texture(RTT)技术的应用
  13. meta 标签汇总
  14. 使用EF+ASP.NET MVC+Bootstrap开发一个功能强大的问卷调查系统
  15. Jedis连接 HelloWorld实现
  16. windows下《Go Web编程》之Go工作空间
  17. Python正则表达式使用
  18. THREE.JS(如何想场景中添加物体对象)
  19. 【转】TCP建立连接三次握手和释放连接四次握手
  20. SQL 处理排序空值

热门文章

  1. Eclipse初体验
  2. Charles(网络封包分析工具)
  3. OneThink视图模型进行组合查询!文档组合文档详情
  4. 170726、常用 Git 命令清单
  5. 报警告session_regenerate_id(): Failed to create(read) session ID: files (path: N;/path)
  6. Maven 的聚合(多模块)和 Parent 继承
  7. Python开发【模块】:Concurrent
  8. 002-Spring Framework-Core-01-IoC容器
  9. AE开发的一个想法
  10. 总结工作中常用的PHP代码