From d7471ab436cbed865d434eeea06b9cd4d48148bf Mon Sep 17 00:00:00 2001 From: sh0723 Date: Tue, 9 Jun 2026 01:25:39 +0900 Subject: [PATCH] =?UTF-8?q?16234=20:=20=EC=9D=B8=EA=B5=AC=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ16234/BOJ16234_V1.cpp | 93 ++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/week3/BOJ16234/BOJ16234_V1.cpp diff --git a/src/week3/BOJ16234/BOJ16234_V1.cpp b/src/week3/BOJ16234/BOJ16234_V1.cpp new file mode 100644 index 0000000..5b46ae7 --- /dev/null +++ b/src/week3/BOJ16234/BOJ16234_V1.cpp @@ -0,0 +1,93 @@ +#include +using namespace std; +vector> country_map; +vector> visited; +vector>> connected_country; +vector avg_people_cnt; +int dy[4] = {-1, 0, 1, 0}; +int dx[4] = {0, 1, 0, -1}; +int N,L,R; + +void dfs(int y, int x, int comp_num, bool &found) { + visited[y][x] = comp_num; + 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 < N) { + int diff = abs(country_map[ny][nx] - country_map[y][x]); + if (visited[ny][nx] == 0 && diff >= L && diff <= R) { + found = true; + dfs(ny, nx, comp_num, found); + } + } + } + if (found == false) { + visited[y][x] = 0; + } +} +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> N >> L >> R; + + for (int i=0; i()); + visited.push_back(vector()); + for (int j=0; j> temp; + country_map[i].push_back(temp); + visited[i].push_back(0); + } + } + int day_cnt = 0; + while(true) { + bool not_present = true; + int comp_num = 1; + for (int i=0; i>()); + for (int i=0; i> comp : connected_country) { + int people_cnt = 0; + for (pair p : comp) { + people_cnt += country_map[p.first][p.second]; + } + + people_cnt = people_cnt / comp.size(); + for (pair p : comp) { + country_map[p.first][p.second] = people_cnt; + } + } + connected_country.clear(); + fill(visited.begin(), visited.end(), vector(N,0)); + day_cnt++; + } + + cout << day_cnt << endl; + + return 0; +} \ No newline at end of file