Skip to content

Conversation

@KII1ua
Copy link
Contributor

@KII1ua KII1ua commented Jan 8, 2026

🚀 이슈 번호

Resolve: {#2284}

🧩 문제 해결

스스로 해결: ✅ 30m

🔎 접근 과정

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

  • 🔹 어떤 알고리즘을 사용했는지 dfs, dp
  • 🔹 어떤 방식으로 접근했는지
    N이 500이여서 단순 깊이우선탐색을 하면 O(N^4)으로 시간초과가 날 수 있다고 생각하여 이전에 값을 다시 사용하는 dp테이블을 만들어 관리해야겠다고 생각했습니다. 모든 칸에대해서 dp배열이 0값이 아닌 경우 이미 탐색을 수행했다는 의미이므로 바로 값을 리턴하여 최댓값으로 갱신하였습니다.

⏱️ 시간 복잡도

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

  • Big-O 표기법: O(N^2)
  • 이유:
    모든 칸에 대해서 dfs하지만 값을 재사용하여 중복된 곳을 찾지 않음

💻 구현 코드

#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;
int graph[501][501];
int dp[501][501];

int func(int x, int y) {
    if(x >= N || x < 0 || y >= N || y < 0) return 0;
    int &ret = dp[x][y];

    if(ret != 0) {
        return ret;
    }

    ret = 1;

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

        if(nx >= N || nx < 0 || ny >= N || ny < 0) continue;

        if(graph[x][y] < graph[nx][ny]) {
            ret = max(ret, func(nx, ny) + 1);
        }
    }

    return ret;
}

void solve() {
    int answer = 0;

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            if(dp[i][j] == 0) {
                answer = max(func(i, j), answer);
            }
        }
    }
    
    cout << answer;
}

void input() {
    cin >> N;

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            cin >> 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 linked an issue Jan 8, 2026 that may be closed by this pull request
@KII1ua KII1ua merged commit 49ba9a6 into main Jan 12, 2026
1 check passed
@KII1ua KII1ua deleted the sungyoon_1937 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