The time limit of 10 seconds, suddenly stunned, think of a n^5 solution, decisive to write.
Use F[I1][J1][I2][J2] to indicate how much of the same line starts from the (i1,j1) and B matrices (i2,j2) of the A matrix.
Then enumerate the i1,i2,j1,j2 and then judge a few lines.
1#include <iostream>2#include <cstdio>3 using namespacestd;4 intN;5 intans=0;6 Long Longa[ -][ -],b[ -][ -];7 intf[ -][ -][ -][ -];8 intMain ()9 {Tenscanf"%d",&n); One for(intI=1; i<=n;i++) A { - for(intj=1; j<=n;j++) -scanf"%lld",&a[i][j]); the } - for(intI=1; i<=n;i++) - { - for(intj=1; j<=n;j++) +scanf"%lld",&b[i][j]); - } + for(inti1=1; i1<=n;i1++) A { at for(intj1=1; j1<=n;j1++) - { - for(intI2=1; i2<=n;i2++) - { - for(intJ2=1; j2<=n;j2++) - { in intt=0; - while(t+j1<=n && t+j2<=n && a[i1][j1+t]==b[i2][j2+t]) t++; to if(t<0) t=0; +f[i1][j1][i2][j2]=T; - } the } * } $ }Panax Notoginseng for(inti1=1; i1<=n;i1++) - { the for(intj1=1; j1<=n;j1++) + { A for(intI2=1; i2<=n;i2++) the { + for(intJ2=1; j2<=n;j2++) - { $ intnow=F[i1][j1][i2][j2]; $ if(now==0)Continue; - intt=1; - if(ans==0) ans=1; the while(now && t+i1<=n && t+i2<=N) - {Wuyi if(F[i1+t][j1][i2+t][j2]<now) now=f[i1+t][j1][i2+T] [J2]; theAns=max (Ans,min (t+1, now)); -t++; Wu } - } About } $ } - } -printf"%d\n", ans); - return 0; A } +
View Code
Bzoj 1567 [Jsoi2008]blue Mary's battle map