Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dohyeondol1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <iostream>
#include <vector>
using namespace std;

int height, width;
int visited[320001];
char grid[201][201];
vector<int> 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;
}