From 41397db9467fabbc8a812d9cc4dccf2297be80bb Mon Sep 17 00:00:00 2001 From: sh0723 Date: Thu, 25 Jun 2026 15:18:41 +0900 Subject: [PATCH] =?UTF-8?q?1987=20:=20=EC=95=8C=ED=8C=8C=EB=B2=B3=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ1987/BOJ1987_V1.cpp | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/week3/BOJ1987/BOJ1987_V1.cpp diff --git a/src/week3/BOJ1987/BOJ1987_V1.cpp b/src/week3/BOJ1987/BOJ1987_V1.cpp new file mode 100644 index 0000000..9000b5d --- /dev/null +++ b/src/week3/BOJ1987/BOJ1987_V1.cpp @@ -0,0 +1,46 @@ +#include +using namespace std; +int inp[20][20], visited[20][20]; +int dy[4] = {0,0,1,-1}; +int dx[4] = {1,-1,0,0}; +map ret; +int R,C; +int max_val = INT_MIN; +void dfs(int y, int x, int level) { + visited[y][x] = 1; + ret[inp[y][x]] = 1; + for (int i = 0; i < 4; i++) { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 0 || ny >= R || nx < 0 || nx >= C) continue; + if (visited[ny][nx]) continue; + + if (ret.find(inp[ny][nx]) != ret.end()) continue; + dfs(ny, nx, level + 1); + } + visited[y][x] = 0; + ret.erase(inp[y][x]); + max_val = max(max_val, level); +} +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> R >> C; + + for (int i=0; i> s; + for (int j=0; j