Last active
September 8, 2015 06:40
-
-
Save hhjeong/e342d5909ce04fe5d0ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int N, M; | |
int R[30][30] = {0}; | |
bool isEmpty( int si, int ei, int sj, int ej ) { | |
for( int i = si ; i <= ei ; ++i ) | |
if( R[i][ej]-R[i][sj-1] != (ej-sj)+1 ) return false; | |
return true; | |
} | |
int main() { | |
cin >> N >> M; | |
for( int i = 1 ; i <= N ; ++i ) { | |
char tmp[30]; | |
cin >> tmp; | |
for( int j = 1 ; j <= M ; ++j ) { | |
R[i][j] = 1 - (tmp[j-1]-'0'); | |
R[i][j] += R[i][j-1]; | |
} | |
} | |
int best = 0; | |
for( int i = 1 ; i <= N ; ++i ) { | |
for( int j = 1 ; j <= M ; ++j ) { | |
for( int k = i ; k <= N ; ++k ) { | |
for( int l = j ; l <= M ; ++l ) { | |
if( isEmpty( i, k, j, l ) ) { | |
int width = l-j+1; | |
int height = k-i+1; | |
best = max( best, (width+height)*2 ); | |
} | |
} | |
} | |
} | |
} | |
cout << best << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment