From 78912508dd5be89b5552dda43309492386e5fee6 Mon Sep 17 00:00:00 2001 From: Do Hyeon Seok Date: Mon, 14 Jul 2025 01:24:29 +0900 Subject: [PATCH] 2025-07-14 --- dohyeondol1/README.md | 2 + .../21-dohyeondol1.cpp" | 86 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 "dohyeondol1/\352\267\270\353\236\230\355\224\204 \354\235\264\353\241\240/21-dohyeondol1.cpp" diff --git a/dohyeondol1/README.md b/dohyeondol1/README.md index f44924f..0d4f5bc 100644 --- a/dohyeondol1/README.md +++ b/dohyeondol1/README.md @@ -21,3 +21,5 @@ | 17차시 | 2025.06.26 | 기하학 | [선분 교차 2](https://www.acmicpc.net/problem/17387)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/65| | 18차시 | 2025.07.04 | 기하학 | [Water Testing](https://www.acmicpc.net/problem/16057)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/70| | 19차시 | 2025.07.09 | 그래프 이론 | [최소 스패닝 트리](https://www.acmicpc.net/problem/1197)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/76| + | 20차시 | 2025.07.10 | 문자열 | [접두사](https://www.acmicpc.net/problem/1141)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/78| + | 21차시 | 2025.07.14 | 그래프 이론 | [석고 모형 만들기](https://www.acmicpc.net/problem/32031)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/81| diff --git "a/dohyeondol1/\352\267\270\353\236\230\355\224\204 \354\235\264\353\241\240/21-dohyeondol1.cpp" "b/dohyeondol1/\352\267\270\353\236\230\355\224\204 \354\235\264\353\241\240/21-dohyeondol1.cpp" new file mode 100644 index 0000000..16275b1 --- /dev/null +++ "b/dohyeondol1/\352\267\270\353\236\230\355\224\204 \354\235\264\353\241\240/21-dohyeondol1.cpp" @@ -0,0 +1,86 @@ +#include +#include +using namespace std; + +int height, width; +int visited[320001]; +char grid[201][201]; +vector graph[320001]; + +void dfs(int u) { + if(visited[u]) + return; + visited[u] = true; + + for(int v : graph[u]) + dfs(v); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + cin >> height >> width; + for(int i = 0; i < height; ++i) { + for(int j = 0; j < width; ++j) { + int base = (i * width + j) * 8; + char ch; + cin >> ch; + + int mask = 0; + if(ch == 'H') mask = 1; + else if(ch == 'I') mask = 2; + else if(ch == 'O') mask = 4; + + for(int k = 0; k < 8; ++k) + graph[base + k].push_back(base + (k ^ mask)); + } + } + + for(int i = 0; i < height; ++i) { + for(int j = 0; j < width - 1; ++j) { + int u = (i * width + j) * 8; + int v = (i * width + (j + 1)) * 8; + + graph[u+1].push_back(v); + graph[v].push_back(u + 1); + + graph[u+3].push_back(v+2); + graph[v+2].push_back(u+3); + + graph[u+5].push_back(v+4); + graph[v+4].push_back(u+5); + + graph[u+7].push_back(v+6); + graph[v+6].push_back(u+7); + } + } + + for(int i = 0; i < height - 1; ++i) { + for(int j = 0; j < width; ++j) { + int u = (i * width + j) * 8; + int v = ((i + 1) * width + j) * 8; + + graph[u+2].push_back(v); + graph[v].push_back(u+2); + + graph[u+3].push_back(v+1); + graph[v+1].push_back(u+3); + + graph[u+6].push_back(v+4); + graph[v+4].push_back(u+6); + + graph[u+7].push_back(v+5); + graph[v+5].push_back(u+7); + } + } + + int cnt = 0; + for(int i = 0; i < height * width * 8; ++i) { + if(visited[i]) continue; + dfs(i); + cnt++; + } + + cout << cnt << '\n'; + return 0; +} \ No newline at end of file