60pts求条
查看原帖
60pts求条
560112
__Alexander__楼主2024/11/28 14:38

rt

#include <bits/stdc++.h> 
using namespace std;
int n,l,s;
string ss[300005];
int bs=1145,mod=10114523;
int pw[300005];
int hush[300005][205];
int hs[300005];
long long ans=0;
int main(){
    // freopen("test.in","r",stdin);
    // freopen("test.out","w",stdout);
	cin>>n>>l>>s;
    for (int i=1;i<=n;i++){
        cin>>ss[i];
    }
    pw[0]=1;
    for (int i=1;i<=l;i++){
        pw[i]=pw[i-1]*bs;
    }
    for (int i=1;i<=n;i++){
        for (int j=1;j<=l;j++){
            hush[i][j]=(hush[i][j-1]*bs+ss[i][j-1])%mod;
        }
    }
    for (int i=1;i<=l;i++){
        for (int j=1;j<=n;j++){
            hs[j]=(hush[j][i-1]*pw[l-i]+hush[j][l]-hush[j][i]*pw[l-i])%mod;
        }
        sort(hs+1,hs+n+1);
        int tt=1;
        for (int j=1;j<=n;j++){
            if (hs[j]!=hs[j-1]){
                tt=1;
            }
            else{
                ans+=tt;
                tt++;
            }
        }
    }
    cout<<ans<<endl;
	return 0;
}
2024/11/28 14:38
加载中...