Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Created November 5, 2019 08:19
Show Gist options
  • Save pinglunliao/bd57d348db119c0d60660e7e779ecc09 to your computer and use it in GitHub Desktop.
Save pinglunliao/bd57d348db119c0d60660e7e779ecc09 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main()
{
int board[100][100] = {0};
int h, w;
cin >> h >> w;
// 因為題目可蓋城堡是用 0 表示,
// 所以將 0 變 1、1 變 0,來配合演算法
for(int i = 0; i < h; i++)
{
for(int j = 0; j < w; j++)
{
cin >> board[i][j];
board[i][j] = 1 - board[i][j];
}
}
int maxSqLen = 0;
for(int i = 1; i < h; i++)
{
for(int j = 1; j < w; j++)
{
if(board[i-1][j-1] >= 1 && board[i][j] == 1)
{
board[i][j] = min(board[i][j-1], min(board[i-1][j-1], board[i-1][j])) + 1;
maxSqLen = max(maxSqLen, board[i][j]);
}
}
}
int area = maxSqLen * maxSqLen;
cout << area << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment