Main topic:
There are a number of strings, which are two equal-length and exactly one-bit logarithm of a different string.
Ideas:
Hash Dafa good! are going backwards each time (the base is different), then enumerate the different one, before and after two paragraphs together in order to have a distinction between the first part and multiply a number. Modulus is naturally overflow with unsigned long long.
Code:
1#include <cstdio>2#include <iostream>3#include <algorithm>4 using namespacestd;5 Const ints1=1007, s2=10007;6 Chars[ About];7UnsignedLong Longl[30010][ About],r[30010][ About],a[30010];8 9 intMain ()Ten { One intn,m,op,i,j,sum=0; Ascanf"%d%d%d",&n,&m,&op); - for(i=1; i<=n;i++) - { thescanf"%s", s+1); - for(j=1; j<=m;j++) l[i][j]=l[i][j-1]*s1+S[j]; - for(j=m;j>=1; j--) r[i][j]=r[i][j+1]*s2+S[j]; - } + for(i=1; i<=m;i++) - { + for(j=1; j<=n;j++) a[j]=l[j][i-1]*233+r[j][i+1]; ASort (A +1, a+n+1); at intans=0; - for(j=2; j<=n;j++) - if(a[j]==a[j-1]) ans++,sum+=ans; - Elseans=0; - } -printf"%d", sum); in return 0; -}
BZOJ3555 [Ctsc2014] Penguin QQ