Reference: http://hzwer.com/5153.html
Of course, two points can be replaced by a hash table.
#include <cstdio> #include <iostream> #include <cstring>using namespace std; #define MOD 2501typedef unsigned long long ull;const ull seed1=3659,seed2=1789;ull sum[51][51],sum2[51][51],v[mod],pow1[51],pow2[51];int N, Ans,first[mod],next[mod],en;void Insert (const ull &v) {int u= (int) (V%MOD); v[en]=v;next[en]=first[u];first[u]=en ++;} BOOL Check (const int &x) {memset (first,-1,sizeof (first)); en=0;for (int i=x;i<=n;i++) for (int. j=x;j<=n;j++) in SERT (Sum[i][j]-sum[i-x][j]*pow1[x]-sum[i][j-x]*pow2[x]+sum[i-x][j-x]*pow1[x]*pow2[x]); for (int i=x;i<=n;i++) for (int j=x;j<=n;j++) {ull t=sum2[i][j]-sum2[i-x][j]*pow1[x]-sum2[i][j-x]*pow2[x] +sum2[i-x][j-x]*pow1[x] *POW2[X]; int o= (int) (T%MOD); for (int i=first[o];i!=-1;i=next[i]) if (T==v[i]) return 1; }return 0;} int main () {scanf ("%d", &n), for (Int. i=1;i<=n;++i) for (int j=1;j<=n;++j) cin>>sum[i][j];for (int i=1;i <=n;++i) for (int j=1;j<=n;++j) cin>>sum2[i][j];for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) sum[i][j]+=sum[i-1][j]*seed1;for (int. i=1;i<=n;++i) for (int j=1;j<=n;++j) sum[i][j]+=sum[i][j-1]*seed2;for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) sum2[i][j]+=sum2[i-1][j]*seed1;for ( int i=1;i<=n;++i) for (int j=1;j<=n;++j) sum2[i][j]+=sum2[i][j-1]*seed2;pow1[0]=pow2[0]=1; for (int i=1;i<=n;i++) pow1[i]=pow1[i-1]*seed1, Pow2[i]=pow2[i-1]*seed2;int l=1,r=n;while (l<=r) {int mid=l+r >>1;if (check (mid)) Ans=mid,l=mid+1;else r=mid-1; }printf ("%d\n", ans); return 0;}
Character Matrix hash, dichotomy answer, hash table bzoj1567 [Jsoi2008]blue Mary's campaign map