#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
vector<int> kmp(string s){
vector<int>res(sz(s));
for(int i=1,j=0;i<sz(s);i++){
while(j and s[i]!=s[j])j=res[j-1];
if(s[i]==s[j])j++;
res[i]=j;
}
return res;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
string s,t;
cin>>s>>t;
int n=sz(s);
int m=sz(t);
vi ans(3,0);
for(int i=0;i<n;i++){
string s1=s.substr(0,i),s2=s.substr(i,sz(s)-i);
reverse(all(s1));
string t1=t,t2=t;
reverse(all(t2));
vector<int>p1=kmp(s1+"#"+t1);
vector<int>p2=kmp(s2+"#"+t2);
for(int j=0;j<m;j++){
int x=p1[i+j+1]+p2[n-i+m-j-1];
if(x>ans[0]){
ans[0]=x;
ans[1]=i-p1[i+j+1]+1;
ans[2]=j+1-p1[i+j+1];
//cout<<i<<' ';
}
}
}
reverse(all(t));
for(int i=0;i<n;i++){
string s1=s.substr(0,i),s2=s.substr(i,sz(s)-i);
reverse(all(s1));
string t1=t,t2=t;
reverse(all(t2));
vector<int>p1=kmp(s1+'#'+t1);
vector<int>p2=kmp(s2+'#'+t2);
for(int j=0;j<m;j++){
int x=p1[i+j+1]+p2[n-i+m-j-1];
if(x>=ans[0]){
ans[0]=x;
ans[1]=i-p1[i+j+1]+1;
ans[2]=m-j-1-p2[n-i+m-j-1];
}
}
}
cout<<ans[0]<<'\n'<<ans[1]<<' '<<ans[2]<<'\n';
}
/*
input:
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
139 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |