Can someone tell me what am I doing wrong?

Problem: https://codeforces.com/contest/22/problem/B

Editorial: https://codeforces.com/blog/entry/507 ( I followed the DP solution O((n*m)^2) )

My approach: rectangle with coordinates (x1, y1, x2, y2) is correct if and only if rectangles (x1, y1, x2-1, y2) and (x1, y1, x2, y2-1) are correct, and board[x2][y2] = ‘0’.

If it is correct then find it’s perimeter and if it’s greater then answer then answer=perimeter ie ans=max(ans,dp[i][j][p][q])

so dp[ i ][ j ][ i ][ j ]=1 for all i,j when v[i][j]==0. Because from point p1 to point p1, ie the same point always have a perimeter is the base case.

`signed main(){ int r,c;cin>>r>>c; vector<vi> v(r,vi(c));//2d array v[r][c] bool dp[25][25][25][25]={false};//i,j to p,q for(int i=0;i<r;i++){ string s;cin>>s; for(int j=0;j<c;j++){ v[i][j]=(s[j]-'0'); if(v[i][j]==0)dp[i][j][i][j]=true; } } int ans=-1; for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ for(int p=i;p<r;p++){ for(int q=j;q<c;q++){ //i,j to p,q , 0,0 0,2, afrom 1 to p, b from 1 to q if(!(i==p && j==q)){ if(p-1>=0 && q-1>=0) dp[i][j][p][q]=(dp[i][j][p-1][q] && dp[i][j][p][q-1] && (v[p][q]==0)); if(dp[i][j][p][q]==true){ ans=max(ans,2*(p-i+q-j+2)); } } } } } } cout<<ans; } `