#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
#define X first
#define Y second
int board[102][102];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n,mx=0;
cin >> n;
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
cin >> board[i][j];
if(board[i][j]>mx) mx=board[i][j];
}
}
int res=0;
for(int i=0; i<=mx; i++) {
bool vis[102][102]={0};
queue<pair<int,int>> q;
//비내려서 잠긴 곳 표시
for(int x=0; x<n; x++) {
for(int y=0; y<n; y++) {
if(board[x][y]<=i) vis[x][y]=1;
}
}
int area=0;
for(int x=0; x<n; x++) {
for(int y=0; y<n; y++) {
//잠김
if(vis[x][y]==1) continue;
//안잠김
area++;
q.push({x,y});
vis[x][y]=1;
while(!q.empty()) {
pair<int,int> cur=q.front();
q.pop();
for(int idx=0; idx<4; idx++) {
int nx=cur.X+dx[idx];
int ny=cur.Y+dy[idx];
if(nx<0 || nx>=n || ny<0 || ny>=n) continue;
if(vis[nx][ny]) continue;
vis[nx][ny]=1;
q.push({nx,ny});
}
}
}
}
res=max(res,area);
}
cout << res;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: