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 ;
}

Educational Codeforces Round 17 C. Two strings 打表二分的更多相关文章

  1. Educational Codeforces Round 17

    Educational Codeforces Round 17 A. k-th divisor 水题,把所有因子找出来排序然后找第\(k\)大 view code //#pragma GCC opti ...

  2. Educational Codeforces Round 12 C. Simple Strings 贪心

    C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves si ...

  3. Educational Codeforces Round 17 颓废记

    又被虐了... (记一次惨痛的Codeforces) 好不容易登上去了Codeforces,22:35准时开打 第一题,一看:这不SB题嘛?直接枚举因数上啊.9min才过掉了pretest 第二题.. ...

  4. Educational Codeforces Round 17 D. Maximum path DP

    题目链接:http://codeforces.com/contest/762/problem/D 多多分析状态:这个很明了 #include<bits/stdc++.h> using na ...

  5. Codeforces Educational Codeforces Round 17 Problem.A kth-divisor (暴力+stl)

    You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist ...

  6. Educational Codeforces Round 37 G. List Of Integers (二分,容斥定律,数论)

    G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard ...

  7. Educational Codeforces Round 11 C. Hard Process 前缀和+二分

    题目链接: http://codeforces.com/contest/660/problem/C 题意: 将最多k个0变成1,使得连续的1的个数最大 题解: 二分连续的1的个数x.用前缀和判断区间[ ...

  8. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  9. Educational Codeforces Round 5

    616A - Comparing Two Long Integers    20171121 直接暴力莽就好了...没什么好说的 #include<stdlib.h> #include&l ...

随机推荐

  1. ios获取设备手持方向——电子罗盘

    转:http://book.51cto.com/art/201411/457105.htm 2014-11-15 19:07 张亚飞/崔巍 中国铁道出版社 字号:T | T 综合评级: 想读()  在 ...

  2. jenkins前端构建

    nginx 安装yum install nginx //输入下载 or yum install epel-release //如果上一步安装失败 yum install nginx //再次下载 配置 ...

  3. ubuntu系统下用kazam软件录制的视频不能在windows系统下播放的解决方案

    遇到问题: 在做计算机视觉课程作业,运动目标检测与跟踪时,在ubuntu系统下用kazam录制了一小段运动目标检测的视频,然后在课上展示时播放不出来,想着Mp4格式的不应该播放不出来啊.网上寻求了一番 ...

  4. POI官网中的例子

    官方指南中的例子: http://poi.apache.org/spreadsheet/quick-guide.html#New+Sheet 这一节 Workbook wb = new HSSFWor ...

  5. 电子商务(电销)平台中订单模块(Order)数据库设计明细

    电子商务(电销)平台中订单模块(Order)数据库设计明细 - sochishun - 博客园 http://www.cnblogs.com/sochishun/p/7040628.html 电子商务 ...

  6. string unicode utf8 ascii in python and js

    http://www.jb51.net/article/62155.htm http://www.cnblogs.com/dkblog/archive/2011/03/02/1980644.html ...

  7. nginx:服务器集群

    一.Nginx的事件处理机制 对于一个基本的web服务器来说,事件通常有三种类型,网络事件.信号.定时器. 首先看一个请求的基本过程:建立连接---接收数据---发送数据 . 再次看系统底层的操作 : ...

  8. 实现IT服务弹性伸缩的利器

    随着互联网业务快速持续增长,IT资源使用量按需变化成为常态,这就要求信息部门能快速响应资源使用的变化要求,对运维提出不小挑战.比如电商.在线教育等企业经常推出一些秒杀.抢红包活动,在特定时间段对资源的 ...

  9. Silverlight中ListBox的数据绑定

    在Silverlight中ListBox是一个非常强大的控件.总结下ListBox的绑定数据的方式. 首先,新建一个Book类, public class Book { public string B ...

  10. Maven安装(linux系统)

    解压: 修改配置: export JAVA_HOME=/usr/java/jdk1..0_80 export MAVEN_HOME=/software/apache-maven- export PAT ...