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>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
const ll M=1002887;
const ll mod[5]={1000081,1000231,1000999,1002341,1002887};
const ll inf=1e18+10;
string s,t;
int b[5][M];
ll p[28][5],pp;
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>s>>t;
p[0][0]=p[0][1]=p[0][2]=p[0][4]=p[0][3]=1;
pp=3001;
for(int i=1;i<28;i++){
for(int j=0;j<5;j++){
p[i][j]=p[i-1][j]*pp;
p[i][j]%=mod[j];
}
}
for(int i=0;i<s.size();i++){
ll cur[5];
cur[0]=cur[1]=cur[2]=cur[3]=cur[4]=0;
bool chk=0;
for(int j=i;j<inf;j++){
j%=s.size();
if(chk&&j==i)
break;
for(int k=0;k<5;k++)
cur[k]+=p[s[j]-'a'+1][k],cur[k]%=mod[k],b[k][cur[k]]=max(b[k][cur[k]],i+1);
chk=1;
}
}
ll ans=0,ans1=0,ans2=0;
for(int i=0;i<t.size();i++){
ll cur[5];
cur[0]=cur[1]=cur[2]=cur[3]=cur[4]=0;
ll cnt=0;
for(int j=i;j<inf;j++){
cnt++;
if(cnt==t.size()+1)
break;
j%=t.size();
bool chk=1;
map<ll,ll>mp;
for(int k=0;k<5;k++){
cur[k]+=p[t[j]-'a'+1][k],cur[k]%=mod[k];
chk&=(b[k][cur[k]]>0);
mp[b[k][cur[k]]]++;
}
if(chk){
if(ans<cnt){
ans=cnt;
for(auto it:mp){
if(it.S>=3){
ans1=it.F;
}
}
ans2=i+1;
}
}
}
}
cout<<ans<<'\n'<<ans1-1<<' '<<ans2-1;
}
Compilation message (stderr)
necklace.cpp: In function 'int main()':
necklace.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i=0;i<s.size();i++){
| ~^~~~~~~~~
necklace.cpp:41:18: 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 i=0;i<t.size();i++){
| ~^~~~~~~~~
necklace.cpp:47:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | if(cnt==t.size()+1)
| ~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |