From 7705ccc31169312d9a6bae94ad587f0e34f25612 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Wed, 3 Jun 2026 15:51:08 +0900 Subject: [PATCH] =?UTF-8?q?2636=20:=20=EC=B9=98=EC=A6=88=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week2/BOJ2636/BOJ2636_V1.cpp | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/week2/BOJ2636/BOJ2636_V1.cpp diff --git a/src/week2/BOJ2636/BOJ2636_V1.cpp b/src/week2/BOJ2636/BOJ2636_V1.cpp new file mode 100644 index 0000000..062be5e --- /dev/null +++ b/src/week2/BOJ2636/BOJ2636_V1.cpp @@ -0,0 +1,54 @@ +#include +using namespace std; +int inp_map[100][100]; +int visited[100][100]; +vector> cheese; +int dy[4] = {0, 1, 0, -1}; +int dx[4] = {1, 0, -1, 0}; +int cnt; +int cheese_size; +int N,M; + +void dfs(int y, int x) { + if (inp_map[y][x] == 1) { + cheese.push_back(make_pair(y, x)); + visited[y][x] = 1; + return; + } + visited[y][x] = 1; + + for (int i = 0; i < 4; i++) { + int ny = y + dy[i]; + int nx = x + dx[i]; + if (ny < 0 || nx < 0 || ny >= N || nx >= M) continue; + if (visited[ny][nx] == 0) dfs(ny, nx); + } +} + +int main() { + + cin >> N >> M; + + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + cin >> inp_map[i][j]; + } + } + + while(true) { + fill(&visited[0][0], &visited[0][0] + 100 * 100, 0); + dfs(0, 0); + if (cheese.empty()) break; + cnt++; + cheese_size = cheese.size(); + for (pair chee : cheese) { + int y = chee.first; + int x = chee.second; + inp_map[y][x] = 0; + } + cheese.clear(); + } + + cout << cnt << "\n" << cheese_size << "\n"; + return 0; +} \ No newline at end of file