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 <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#define LL long long
#define pli pair<LL,int>
#define ff first
#define ss second
#define MOD 1000000007
using namespace std;
char s1[1555],s2[1555];
LL mul[1555];
LL hash1[1555],hash2[1555];
vector<pli> res;
int main(){
int len1,len2,len;
scanf("%s %s",s1,s2);
len1=strlen(s1); len2=strlen(s2);
len=min(len1,len2);
mul[0]=1;
for(int i=1;i<26;i++) mul[i]=(mul[i-1]*len)%MOD;
int ans=0;
for(int i=0;i<len1;i++) hash1[i]=mul[s1[i]-'a'],res.push_back({hash1[i],1});
for(int i=0;i<len2;i++) hash2[i]=mul[s2[i]-'a'],res.push_back({hash2[i],2});
sort(res.begin(),res.end());
for(int i=1;i<res.size();i++){
if(res[i-1].ff==res[i].ff && res[i-1].ss+res[i].ss==3) ans=1;
}
for(int i=1;i<len;i++){
res.clear();
for(int j=len1-1;j>=i-1;j--) hash1[j]=(hash1[j-1]+mul[s1[j]-'a'])%MOD,res.push_back({hash1[j],1});
for(int j=len2-1;j>=i-1;j--) hash2[j]=(hash2[j-1]+mul[s2[j]-'a'])%MOD,res.push_back({hash2[j],2});
sort(res.begin(),res.end());
for(int j=1;j<res.size();j++){
if(res[j-1].ff==res[j].ff && res[j-1].ss+res[j].ss==3) ans=i+1;
}
}
printf("%d",ans);
return 0;
}
Compilation message (stderr)
interval.cpp: In function 'int main()':
interval.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<res.size();i++){
~^~~~~~~~~~~
interval.cpp:42:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=1;j<res.size();j++){
~^~~~~~~~~~~
interval.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s %s",s1,s2);
~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |