#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX = 101;
int visited[MAX][MAX];
vector<vector<int>> map;
int M, N;
struct Move {
int x, y;
};
Move mv[4] = { {1,0}, {-1,0}, {0,1}, {0,-1} };
int dfs(int i, int j,int count) {
visited[i][j] = 1;
for (int k = 0; k < 4; k++) {
int movei = i + mv[k].x;
int movej = j + mv[k].y;
if (movei >= 0 && movei < M && movej >= 0 && movej < N) {
if (visited[movei][movej] == -1 && map[movei][movej] == map[i][j]) {
count = dfs(movei, movej, count + 1);
}
}
}
return count;
}
vector<int> solution(int m, int n, vector<vector<int>> picture) {
int number_of_area = 0;
int max_size_of_one_area = 0;
M = m;
N = n;
map = picture;
memset(visited, -1, sizeof(visited));
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (map[i][j] != 0 && visited[i][j] == -1) {
max_size_of_one_area = max(max_size_of_one_area, dfs(i, j, 1));
number_of_area++;
}
}
}
vector<int> answer(2);
answer[0] = number_of_area;
answer[1] = max_size_of_one_area;
return answer;
}
프로그래머스