Skip to content

Conversation

@KII1ua
Copy link
Contributor

@KII1ua KII1ua commented Jan 8, 2026

🚀 이슈 번호

Resolve: {#2286}

🧩 문제 해결

스스로 해결:

🔎 접근 과정

문제 해결을 위한 접근 방식을 설명해주세요.

  • 🔹 어떤 알고리즘을 사용했는지 bfs
  • 🔹 어떤 방식으로 접근했는지
    바깥에 울타리를 만들어 빗물이 1부터 배열 요소의 최댓값 까지 올려서 빈곳을 더해주는 방식으로 구성하였습니다.

⏱️ 시간 복잡도

시간 복잡도 분석을 작성해주세요.
최악의 경우 수행 시간은 어느 정도인지 분석합니다.

  • Big-O 표기법: O(9NM)
  • 이유:
    bfs 9번 수행

💻 구현 코드

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define endl "\n"

struct Tree {
    int Node, left, right;
};

const int INF = 1e9;
const int MAX = 123457;
const int MOD = 1e9 + 7;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int N, M, maxheight;
int graph[51][51];

void bfs(int height) {
    graph[0][0] = height;
    queue<pii> q;
    q.push({0, 0});

    while(!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();

        for(int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];

            if(nx <= N+1 && nx >= 0 && ny <= M+1 && ny >= 0 && graph[nx][ny] < height) {
                graph[nx][ny] = height;
                q.push({nx, ny});
            }
        }
    }
}

void solve() {
    int answer = 0;

    for(int i = 1; i <= maxheight; i++) {
        bfs(i);

        for(int j = 1; j <= N; j++) {
            for(int k = 1; k <= M; k++) {
                if(graph[j][k] < i) {
                    answer++;
                    graph[j][k] += 1;
                }
            }
        }
    }

    cout << answer;
}

void input() {
    cin >> N >> M;

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= M; j++) {
            char a;
            cin >> a;
            graph[i][j] = a - '0';
            maxheight = max(maxheight, graph[i][j]);
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    input();
    solve();
}

@KII1ua KII1ua self-assigned this Jan 8, 2026
@KII1ua KII1ua requested a review from Eunjin3395 as a code owner January 8, 2026 16:20
@KII1ua KII1ua linked an issue Jan 8, 2026 that may be closed by this pull request
@KII1ua KII1ua merged commit 0c7e70d into main Jan 12, 2026
1 check passed
@KII1ua KII1ua deleted the sungyoon_1113 branch January 12, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

260108 : 코딩테스트

2 participants