Skip to content

Commit

Permalink
69-9kyo-hwang
Browse files Browse the repository at this point in the history
  • Loading branch information
9kyo-hwang committed Oct 8, 2024
1 parent 7f2f382 commit e3cb994
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

const vector<pair<int, int>> Offset{{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

vector<vector<int>> Board;

bool OutOfBound(int r, int c)
{
return r < 0 || r >= Board.size() || c < 0 || c >= Board[0].size();
}

int DFS(pair<int, int> ALoc, pair<int, int> BLoc)
{
const auto& [r, c] = ALoc;
if(Board[r][c] == 0)
{
return 0;
}

int Answer = 0;
Board[r][c] = 0;

for(const auto& [dr, dc] : Offset)
{
int nr = r + dr, nc = c + dc;
if(OutOfBound(nr, nc) || Board[nr][nc] == 0)
{
continue;
}

int RetVal = DFS(BLoc, {nr, nc}) + 1;

if(Answer % 2 == 0 && RetVal % 2 == 1) Answer = RetVal;
else if(Answer % 2 == 0 && RetVal % 2 == 0) Answer = max(Answer, RetVal);
else if(Answer % 2 == 1 && RetVal % 2 == 1) Answer = min(Answer, RetVal);
}

Board[r][c] = 1;
return Answer;
}

int solution(vector<vector<int>> InBoard, vector<int> InALoc, vector<int> InBLoc)
{
Board = InBoard;
return DFS({InALoc[0], InALoc[1]}, {InBLoc[0], InBLoc[1]});
}
3 changes: 2 additions & 1 deletion 9-kyo-hwang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@
| 65์ฐจ์‹œ | 2024.9.11 | Greedy | [๋””ํŽœ์Šค ๊ฒŒ์ž„](https://school.programmers.co.kr/learn/courses/30/lessons/142085) | [#224](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/224) |
| 66์ฐจ์‹œ | 2024.9.14 | Sliding Window | [ํ• ์ธ ํ–‰์‚ฌ](https://school.programmers.co.kr/learn/courses/30/lessons/131127) | [#225](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/225) |
| 67์ฐจ์‹œ | 2024.9.23 | Graph Traversal | [ํผ์ฆ ์กฐ๊ฐ ์ฑ„์šฐ๊ธฐ](https://school.programmers.co.kr/learn/courses/30/lessons/84021) | [#228](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/228) |
| 68์ฐจ์‹œ | 2024.10.1 | Greedy | [2024 KAKAO WINTER INTERNSHIP n + 1 ์นด๋“œ ๊ฒŒ์ž„](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#230](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/230) |
| 68์ฐจ์‹œ | 2024.10.1 | Greedy | [2024 KAKAO WINTER INTERNSHIP n + 1 ์นด๋“œ ๊ฒŒ์ž„](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#230](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/230) |
| 69์ฐจ์‹œ | 2024.10.8 | Graph Traversal | [2022 KAKAO BLIND RECRUITMENT ์‚ฌ๋ผ์ง€๋Š” ๋ฐœํŒ](https://school.programmers.co.kr/learn/courses/30/lessons/92345) | [#232](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/232) |

0 comments on commit e3cb994

Please sign in to comment.