#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=3007;
int n,m;
vector<int> prefix_function(string s) {
int n = (int)s.length();
vector<int> pi(n);
for (int i = 1; i < n; i++) {
int j = pi[i-1];
while (j > 0 && s[i] != s[j])
j = pi[j-1];
if (s[i] == s[j])
j++;
pi[i] = j;
}
return pi;
}
vector<int>kmp(string s)
{
int l=sz(s);
vector<int>p(l,0);
for(int i=1;i<l;i++)
{
int j=p[i-1];
while(j>0&&s[i]!=s[j]) j=p[j-1];
if(s[i]==s[j]) j++;
p[i]=j;
}
return p;
}
int ans,x,y;
void solve(string a,string b,bool is)
{
for(int i=0;i<=n;i++)
{
string s="",t="";
for(int j=i;j<n;j++) s+=a[j];
for(int j=0;j<m;j++) t+=b[j];
vector<int>p1=kmp(s+'#'+t);
s="";
for(int j=0;j<i;j++) s+=a[j];
reverse(all(s));
reverse(all(t));
vector<int>p2=kmp(s+'#'+t);
for(int j=0;j<=m;j++)
{
int c=0;
if(i!=n&&j>0) c+=p1[n-i+j];
if(i!=0&&j!=m-1) c+=p2[i+m-j];
if(c>ans)
{
ans=c;
if(i!=0&&j!=m-1)
{
x=i-p2[i+m-j];
if(is) y=m-j-p2[i+m-j];
else y=j-p2[i+m-j];
}
else
{
x=i;
if(is) y=m-j;
else y=j;
}
}
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string a,b;
cin>>a>>b;
n=sz(a),m=sz(b);
solve(a,b,0);
reverse(all(b));
solve(a,b,1);
cout<<ans<<endl<<x<<" "<<y<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |