[CTSC2014]企鹅QQ

再次惨遭卡模数。

但是为什么自然溢出没有被卡。。。。。。。我好绝望啊

这道题思路就是枚举断点,然后看看这个断点左右两侧和哈希值都一样的话就是相似的。

然后就随便判一下即可。

希望大家不要被卡。。。用自然溢出就行了。。。。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int base = 131,mod = 1e9+9;
int n,l,ds;
unsigned long long hsh[30005][205][2];
struct TP{
    unsigned long long x,y;
    bool operator < (const TP &rhs) const {
        return x==rhs.x?y<rhs.y:x<rhs.x;
    }
    bool operator == (const TP &rhs) const {
        return x==rhs.x&&y==rhs.y;
    }
}tp[30005];
char ch[205];
int main() {
    scanf("%d%d%d",&n,&l,&ds);
    for(int i=1;i<=n;i++) {
        scanf("%s",ch+1);
        for(int j=1;j<=l;j++) {
            hsh[i][j][0]=(hsh[i][j-1][0]*base+ch[j]);
        }
        for(int j=l;j;j--) {
            hsh[i][j][1]=(hsh[i][j+1][1]*157+ch[j]);
        }
    }
    long long ans=0;
    for(int i=1;i<=l;i++) {
        for(int j=1;j<=n;j++) {
            tp[j]=(TP){hsh[j][i-1][0],hsh[j][i+1][1]};
        }
        sort(tp+1,tp+n+1);int res=1;
        for(int j=2;j<=n;j++) {
            if(tp[j]==tp[j-1]) ans+=res,res++;
            else res=1;
        }
    }
    cout<<ans<<endl;
    return 0;
}
[CTSC2014]企鹅QQ
我是咸鱼。转载博客请征得博主同意Orz
原文地址:https://www.cnblogs.com/sdfzhsz/p/9753418.html