27pts 求调
查看原帖
27pts 求调
179871
Lithium_Chestnut楼主2024/8/23 15:57
#include<bits/stdc++.h>
#define Std_Maker lhm
#define ll long long
#define ull unsigned long long
using namespace std;
const int base=127,N=2e6+1;
ll n,l,ans,maxn;
string s[N];
ull h[N],p[N],h1,h2;
multiset<ull> hsh;
void makehash(string s,ull h[],ull p[])
{
    p[0]=1;
    ull l=s.length()-1;
    for(int i=1;i<=l;i++)
    {
        h[i]=h[i-1]*base+s[i];
        p[i]=p[i-1]*base;
    }
    return;
}
ull check(string s,ull h[],ull p[],ll l,ll r)
{
    return h[r]-h[l-1]*p[r-l+1];
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        s[i]=" "+s[i];
        ans=0;
        l=s[i].length()-1;
        makehash(s[i],h,p);
        hsh.insert(check(s[i],h,p,1,l));
        for(int len=1;len<=l;len++)
        {
            h1=check(s[i],h,p,1,len),h2=check(s[i],h,p,l-len+1,l);
            if(h1==h2)
            {
                if(hsh.find(h1)!=hsh.end()) ans+=hsh.count(h1);
            }
        }
        if(ans==n) ans--;
        maxn=max(maxn,ans);
    }
    cout<<maxn;
    return 0;
}
2024/8/23 15:57
加载中...