# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
746296 | bgnbvnbv | Necklace (Subtask 4) (BOI19_necklace4) | C++14 | 654 ms | 420 KiB |
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;
ll vc[maxN];
void prefix_function(string &s) {
int n = (int)s.length();
for (int i = 1; i < n; i++) {
int j = vc[i-1];
while (j > 0 && s[i] != s[j])
j = vc[j-1];
if (s[i] == s[j])
j++;
vc[i] = j;
}
}
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]);
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]);
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |