分析
考虑求出 $f[i][j]$ 表示字符串 $i$ 的$1\sim j$ 个字符的 hash 值,$g[i][j]$ 表示字符串 $i$ 的 $j\sim l$ 个字符的 hash 值。
每次枚举删掉哪个字符,然后利用 $f$ 和 $g$ 即可得到每个串的 hash 值。
然后把所有 hash 值排序后比较即可。
代码
// ===================================
// author: M_sea
// website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define re register
using namespace std;
inline int read() {
int X=0,w=1; char c=getchar();
while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
return X*w;
}
const int N=30000+10,L=200+10;
const int BASE1=19260817,BASE2=19491001;
int n,l,ans=0;
char s[L];
unsigned long long f[N][L],g[N][L],h[N];
int main() {
n=read(),l=read(),read();
for (re int i=1;i<=n;++i) {
scanf("%s",s+1);
for (re int j=1;j<=l;++j) f[i][j]=f[i][j-1]*BASE1+s[j];
for (re int j=l;j>=1;--j) g[i][j]=g[i][j+1]*BASE2+s[j];
}
for (re int j=1;j<=l;++j) {
for (re int i=1;i<=n;++i) h[i]=f[i][j-1]*233+g[i][j+1]*666;
sort(h+1,h+n+1);
for (re int i=2,s=1;i<=n;++i) {
if (h[i]==h[i-1]) ans+=s,++s;
else s=1;
}
}
printf("%d\n",ans);
return 0;
}