This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=3e4;
const ll inf=1e18;
const ll mod=1e9+7;
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;
}
ll n;
string s,t;
ll cnt[maxN];
ll ans=0,id1=0,id2=0;
ll cal(bool tt)
{
string a;
for(int i=0;i<=n;i++)
{
a.clear();
for(int j=i;j<n;j++)
{
a.pb(s[j]);
}
a.pb('#');
for(int j=0;j<t.size();j++) a.pb(t[j]);
auto vc=prefix_function(a);
for(int j=0;j<=t.size();j++)
{
cnt[j]=0;
}
for(int j=0;j<=t.size();j++)
{
cnt[j]+=vc[j+n-i];
}
a.clear();
for(int j=i-1;j>=0;j--)
{
a.pb(s[j]);
}
reverse(t.begin(),t.end());
a.pb('#');
for(int j=0;j<t.size();j++) a.pb(t[j]);
vc=prefix_function(a);
for(int j=0;j<=t.size();j++)
{
ll x=cnt[j]+vc[t.size()-j+i];
if(ans<x)
{
ans=x;
id1=i-vc[t.size()-j+i];
if(tt)
{
id1=id1+x-1;
id1=s.size()-id1-1;
}
id2=j-cnt[j];
}
}
reverse(t.begin(),t.end());
}
return ans;
}
ll m;
void solve()
{
cin >> s >> t;
n=s.size();
m=t.size();
cal(0);
reverse(s.begin(),s.end());
cal(1);
cout << ans<<'\n';
cout << id1<<' '<<id2;
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message (stderr)
necklace.cpp: In function 'll cal(bool)':
necklace.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int j=0;j<t.size();j++) a.pb(t[j]);
| ~^~~~~~~~~
necklace.cpp:43:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int j=0;j<=t.size();j++)
| ~^~~~~~~~~~
necklace.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int j=0;j<=t.size();j++)
| ~^~~~~~~~~~
necklace.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int j=0;j<t.size();j++) a.pb(t[j]);
| ~^~~~~~~~~
necklace.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int j=0;j<=t.size();j++)
| ~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |