diff --git "a/9-kyo-hwang/Graph Traversal/\353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.cpp" "b/9-kyo-hwang/Graph Traversal/\353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.cpp" new file mode 100644 index 0000000..c03e4b5 --- /dev/null +++ "b/9-kyo-hwang/Graph Traversal/\353\254\264\354\235\270\353\217\204 \354\227\254\355\226\211.cpp" @@ -0,0 +1,45 @@ +#include +#include +#include + +using namespace std; + +int Merge(vector& Maps, int x, int y) +{ + if(x < 0 || x >= Maps.size() || y < 0 || y >= Maps[0].size() || Maps[x][y] == 'X') + { + return 0; + } + + int Day = Maps[x][y] - '0'; + Maps[x][y] = 'X'; + + return Day + + Merge(Maps, x - 1, y) + + Merge(Maps, x, y + 1) + + Merge(Maps, x + 1, y) + + Merge(Maps, x, y - 1); +} + +vector solution(vector Maps) +{ + vector DaysofStay; + for(int i = 0; i < Maps.size(); ++i) + { + for(int j = 0; j < Maps[0].size(); ++j) + { + if(Maps[i][j] != 'X') + { + DaysofStay.emplace_back(Merge(Maps, i, j)); + } + } + } + + if(DaysofStay.empty()) + { + return {-1}; + } + + sort(DaysofStay.begin(), DaysofStay.end()); + return DaysofStay; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index f8ea7a9..8ed2789 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -61,4 +61,5 @@ | 58차시 | 2024.7.29 | Trie | [14725 개미굴](https://www.acmicpc.net/problem/14725) | [#207](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/207) | | 59차시 | 2024.8.01 | Greedy | [마법의 엘리베이터](https://school.programmers.co.kr/learn/courses/30/lessons/148653) | [#210](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/210) | | 60차시 | 2024.8.05 | Implementation | [과제 진행하기](https://school.programmers.co.kr/learn/courses/30/lessons/176962) | [#213](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/213) | -| 60차시 | 2024.8.08 | Implementation | [테이블 해시 함수](https://school.programmers.co.kr/learn/courses/30/lessons/147354) | [#214](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/214) | \ No newline at end of file +| 61차시 | 2024.8.08 | Implementation | [테이블 해시 함수](https://school.programmers.co.kr/learn/courses/30/lessons/147354) | [#214](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/214) | +| 62차시 | 2024.8.12 | Graph Traversal | [무인도 여행](https://school.programmers.co.kr/learn/courses/30/lessons/154540) | [#217](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/217) | \ No newline at end of file