Link
预处理一下每个串从左往右和从右往左的哈希值。
然后枚举忽略的是哪一位,然后计算出每个串在忽略这一位下的哈希值。
接下来就是要计算有多少对哈希值相同的串,可以通过排序/哈希等方法解决。

#include<cstdio>
#include<algorithm>
using std::sort;
using u64=unsigned long long;
const int N=30007,M=207;
char s[M];int n,l,S;
u64 a[N],hl[N][M],hr[N][M];
void hash(int id)
{
    for(int i=1;i<=l;++i) hl[id][i]=hl[id][i-1]*233+s[i];
    for(int i=l;i>=1;--i) hr[id][i]=hr[id][i+1]*235+s[i];
}
int main()
{
    scanf("%d%d%d",&n,&l,&S);int ans=0;
    for(int i=1;i<=n;++i) scanf("%s",s+1),hash(i);
    for(int j=1;j<=l;++j)
    {
        for(int i=1;i<=n;i++) a[i]=hl[i][j-1]*237+hr[i][j+1]*239;
        sort(a+1,a+1+n);
	for(int i=2,p=1;i<=n;++i) a[i]==a[i-1]? ans+=p++:p=1;
    }
    printf("%d",ans);
}

相关文章:

  • 2022-03-06
  • 2021-12-21
  • 2021-08-10
  • 2021-07-03
  • 2022-01-05
  • 2021-11-17
  • 2021-08-28
  • 2021-07-30
猜你喜欢
  • 2022-02-03
  • 2022-12-23
  • 2022-02-23
  • 2021-09-07
  • 2021-06-17
  • 2021-09-04
  • 2022-02-01
相关资源
相似解决方案