分析
宝崽题,我的代码的正确性存疑,数据太水
方法是将每个点作为矩阵左上角往右最长的串长和往下最长的串长预处理
然后暴力枚举点,随便乱判断一下就过了
#include <iostream> #include <cstdio> using namespace std; const int N=3e2+10; int n,m; int a[N][N]; int ph[N][N],pl[N][N],ans; string s; bool b; int main() { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) scanf("%d",&a[i][j]); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) { int h=0,l=0; for (int k=j;k<=m;k++) for (int p=j;p<=(j+k)/2;p++) if (a[i][p]!=a[i][k-p+j]) break; else if (p==(j+k)/2) h=k-j+1; for (int k=i;k<=n;k++) for (int p=i;p<=(i+k)/2;p++) if (a[p][j]!=a[k-p+i][j]) break; else if (p==(i+k)/2) l=k-i+1; ph[i][j]=h;pl[i][j]=l; } for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) { int mna=min(ph[i][j],pl[i][j]);b=1; for (int k=i;k<=i+mna-1;k++) if (i+ph[k][j]-1>=k) mna=min(mna,ph[k][j]); else { b=0; break; } for (int k=j;k<=j+mna-1;k++) if (j+pl[i][k]-1>=k) mna=min(mna,pl[i][k]); else { b=0; break; } if (b) ans=max(ans,mna); } printf("%d",ans); }