From 624eb885f8d961c558793831eb1edb16e0187887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AC=B8=ED=98=95?= <74577714+alirz-pixel@users.noreply.github.com> Date: Tue, 20 Jan 2026 14:10:51 +0900 Subject: [PATCH] =?UTF-8?q?260120=20:=20[BOJ=201103]=20=EA=B2=8C=EC=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _munhyeong/1103.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 _munhyeong/1103.cpp diff --git a/_munhyeong/1103.cpp b/_munhyeong/1103.cpp new file mode 100644 index 00000000..5f079cc3 --- /dev/null +++ b/_munhyeong/1103.cpp @@ -0,0 +1,64 @@ +#include +#include +#include + +using namespace std; + +struct Info { + int cnt; + int y; + int x; +}; + +int visited[51][51] = { 0, }; + +int dy[4] = { 1, -1, 0, 0 }; +int dx[4] = { 0, 0, 1, -1 }; +int dfs(vector& board, int& r, int& c, int y, int x) { + int &ret = visited[y][x]; + if (ret) return ret; + ret = -1; + + int step = 1; + int move = board[y][x] - '0'; + for (int dir = 0; dir < 4; dir++) { + int ny = y + (move * dy[dir]); + int nx = x + (move * dx[dir]); + + if (ny < 0 || nx < 0 || ny >= r || nx >= c) + continue; + + if (board[ny][nx] == 'H') + continue; + + // visited 검사 + int cur = dfs(board, r, c, ny, nx); + if (cur == -1) + return -1; + step = max(step, cur + 1); + } + + return ret = step; +} + +int main() { + int r, c; + cin >> r >> c; + + vector board(r); + for (int y = 0; y < r; y++) + cin >> board[y]; + + cout << dfs(board, r, c, 0, 0) << "\n"; + + /* + for (int y = 0; y < r; y++) { + for (int x = 0; x < c; x++) { + cout << visited[y][x] << " "; + } + cout << "\n"; + } + */ + + return 0; +}