正解:哈希
解题报告:
传送门$QwQ$
直接$O(len)$枚举哪一位,然后把这一位删了重新拼接起来,存桶里查下就成
$over$?
主要的难点大概在卡哈希+卡常$QAQ$
#includeusing namespace std; #define il inline #define gc getchar() #define mp make_pair #define ri register int #define rc register char #define rb register bool #define ull unsigned long long #define rp(i,x,y) for(ri i=x;i<=y;++i) #define my(i,x,y) for(ri i=x;i>=y;--i) const int N=200+10,M=30000+10,bas1=19260817,bas2=19491001; const ull mod1=20190816170251; int n,l,as; char str[N]; ull poww[N],hsh1[M][N],hsh2[M][N],h1[M][N],h2[M][N],p[N]; pair P[M]; il int read() { rc ch=gc;ri x=0;rb y=1; while(ch!='-' && (ch>'9' || ch<'0'))ch=gc; if(ch=='-')ch=gc,y=0; while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc; return y?x:-x; } il void solv(ri x) { rp(i,1,n) {ri tmp=(hsh1[i][x-1]*poww[l-x+1]%mod1+hsh2[i][x+1])%mod1,t=h1[i][x-1]*1007+h2[i][x+1]*197;P[i]=mp(tmp,t);} sort(P+1,P+1+n);for(ri j=2,s=1;j<=n;++j)if(P[j]==P[j-1])as+=s++;else s=1; //printf("%d\n",as); } int main() { //freopen("4503.in","r",stdin);freopen("4503.out","w",stdout); n=read();l=read();read();poww[0]=1;rp(i,1,l)poww[i]=poww[i-1]*bas1%mod1,p[i]=p[i-1]*bas2; rp(i,1,n) { scanf("%s",str+1); rp(j,1,l)hsh1[i][j]=(hsh1[i][j-1]*bas1%mod1+str[j])%mod1,h1[i][j]=h1[i][j-1]*bas2+str[j]; my(j,l,1)hsh2[i][j]=(hsh2[i][j+1]*bas1%mod1+str[j])%mod1,h2[i][j]=h2[i][j+1]*bas2+str[j]; } rp(i,1,l)solv(i);;printf("%d\n",as); return 0; }