#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define m_p make_pair
#define vec vector
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pw(x) (1LL<<x)
#define sz(x) (int)x.size()
#define endl '\n'
#define pb push_back
#define fast_ioi ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker,"/stack:20000000")
//#pragma GCC target("sse,sse2,sse3,sse3,ssse3,abm,avx,avx2,tune=native")
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T> bool umax(T &a, T b){return (a<b?a=b,1:0);}
template<class T> bool umin(T &a, T b){return (a>b?a=b,1:0);}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef unsigned long long ull;
const int N=3e3+2;
int dp1[N][N];
int dp2[N][N];
int func[2*N];
void calc(int *pf,const string &s){
for(int i=1;i<sz(s);i++){
int j=pf[i-1];
while(j>0 && s[j]!=s[i]){
j=pf[j-1];
}
pf[i]=j;
pf[i]+=(s[i]==s[j]);
}
}
signed main(){
fast_ioi;
string s,t;
cin>>s>>t;
int ans=-1;
int f=-1,se=-1;
int n=sz(s),m=sz(t);
string lel;
{
/// заканчивая в j and staring at i
for(int i=0;i<n;i++){
lel=s.substr(i,n-1)+'#'+t;
int w=(n-1-i+1)+1;
calc(func,lel);
for(int j=0;j<m;j++){
dp1[i][j]=func[j+w];
}
}
/// заканчивая в i and staring at j
for(int j=0;j<m;j++){
lel=t.substr(j,m-1)+'#'+s;
int w=(m-1-j+1)+1;
calc(func,lel);
for(int i=0;i<n;i++){
dp2[i][j]=func[i+w];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
int st1=i-(i?dp2[i-1][j]:0),st2=j-(j?dp1[i][j-1]:0);
int dl=(i?dp2[i-1][j]:0)+(j?dp1[i][j-1]:0);
if(umax(ans,dl)){
f=st1,se=st2;
}
}
}
}
// {
// reverse(all(s));
// /// заканчивая в j and staring at i
// for(int i=0;i<n;i++){
// string lel=s.substr(i,n-1)+'#'+t;
// int w=(n-i)+1;
// calc(func,lel);
// for(int j=0;j<m;j++){
// dp1[i][j]=func[j+w];
// }
// }
// /// заканчивая в i and staring at j
// for(int j=0;j<m;j++){
// string lel=t.substr(j,m-1)+'#'+s;
// int w=(m-j)+1;
// calc(func,lel);
// for(int i=0;i<n;i++){
// dp2[i][j]=func[i+w];
// }
// }
// for(int i=0;i<n;i++){
// for(int j=0;j<m;j++){
// int st1=i+(j?dp1[i][j-1]-1:0),st2=j-(j?dp1[i][j-1]:0);
// int dl=(i?dp2[i-1][j]:0)+(j?dp1[i][j-1]:0);
//// st1=n-st1-1;
// if(umax(ans,dl)){
// f=st1,se=st2;
//
// }
//// debug()<<imie(s)imie(t)imie(i)imie(j)imie(dp1[i][j])imie(dp2[i][j]);
//// print(i);print(j);print()
// }
// }
// reverse(all(s));
// }
//
{
reverse(all(t));
/// заканчивая в j and staring at i
for(int i=0;i<n;i++){
lel=s.substr(i,n-1)+'#'+t;
int w=(n-i)+1;
calc(func,lel);
for(int j=0;j<m;j++){
dp1[i][j]=func[j+w];
}
}
/// заканчивая в i and staring at j
for(int j=0;j<m;j++){
lel=t.substr(j,m-1)+'#'+s;
int w=(m-j)+1;
calc(func,lel);
for(int i=0;i<n;i++){
dp2[i][j]=func[i+w];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
int st1=i-(i?dp2[i-1][j]:0),st2=j+(i?dp2[i-1][j]-1:0);
int dl=(i?dp2[i-1][j]:0)+(j?dp1[i][j-1]:0);
st2=m-st2-1;
if(umax(ans,dl)){
f=st1,se=st2;
// debug()<<imie(j)imie(s)imie(t)imie(i?dp2[i-1][j]:0)imie((j?dp1[i][j-1]:0));
}
}
}
reverse(all(t));
}
assert(ans!=-1);
cout<<ans<<endl<<f<<' '<<se;
return 0;
}
/*
zxyabcd
ztcdabxy
yxbadctz
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
12 ms |
4864 KB |
Output is correct |
7 |
Correct |
12 ms |
4812 KB |
Output is correct |
8 |
Correct |
11 ms |
4572 KB |
Output is correct |
9 |
Correct |
11 ms |
4632 KB |
Output is correct |
10 |
Correct |
10 ms |
4812 KB |
Output is correct |
11 |
Correct |
11 ms |
4684 KB |
Output is correct |
12 |
Correct |
11 ms |
4552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
12 ms |
4864 KB |
Output is correct |
7 |
Correct |
12 ms |
4812 KB |
Output is correct |
8 |
Correct |
11 ms |
4572 KB |
Output is correct |
9 |
Correct |
11 ms |
4632 KB |
Output is correct |
10 |
Correct |
10 ms |
4812 KB |
Output is correct |
11 |
Correct |
11 ms |
4684 KB |
Output is correct |
12 |
Correct |
11 ms |
4552 KB |
Output is correct |
13 |
Correct |
654 ms |
70980 KB |
Output is correct |
14 |
Correct |
608 ms |
71036 KB |
Output is correct |
15 |
Correct |
644 ms |
68356 KB |
Output is correct |
16 |
Correct |
617 ms |
70664 KB |
Output is correct |
17 |
Correct |
545 ms |
69700 KB |
Output is correct |
18 |
Correct |
571 ms |
70752 KB |
Output is correct |
19 |
Correct |
590 ms |
70576 KB |
Output is correct |
20 |
Correct |
607 ms |
69708 KB |
Output is correct |
21 |
Correct |
635 ms |
69860 KB |
Output is correct |