state:
d[i][j] - max square length with i, j as center
transition:
NONE
/* UVas */ /*****************************************************************************/ int t, m, n, q; int p[20][2]; int d[100][100]; char s[100][100]; int calc(int x, int y) { int &r=d[x][y]; if (r!=-1) { return r; } else { r=0; for (int k=0; x-k>=0&&x+k<m&&y-k>=0&&y+k<n; k++) { for (int i=x-k; i<=x+k; i++) { for (int j=y-k; j<=y+k; j++) { if (s[i][j]!=s[x][y]) { return 2*(k-1)+1; } } } r=max(r, 2*k+1); } } return r; } int main(void) { cin>>t; while (t--) { cin>>m>>n>>q; for (int i=0; i<m; i++) { for (int j=0; j<n; j++) { cin>>s[i][j]; } } for (int i=0; i<q; i++) { cin>>p[i][0]>>p[i][1]; } memset(d, -1, sizeof(d)); cout<<m<<" "<<n<<" "<<q<<endl; for (int i=0; i<q; i++) { cout<<calc(p[i][0], p[i][1])<<endl; } } return 0; } /*****************************************************************************/
No comments :
Post a Comment