Skip to content

Instantly share code, notes, and snippets.

@hhjeong
Last active September 8, 2015 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhjeong/e342d5909ce04fe5d0ef to your computer and use it in GitHub Desktop.
Save hhjeong/e342d5909ce04fe5d0ef to your computer and use it in GitHub Desktop.
#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