Skip to content

Conversation

@esc10946
Copy link
Contributor

@esc10946 esc10946 commented Jan 9, 2026

🚀 이슈 번호

Resolve: {#2293}

🧩 문제 해결

스스로 해결:

🔎 접근 과정

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

  • 🔹 어떤 알고리즘을 사용했는지 : 재귀
  • 🔹 어떤 방식으로 접근했는지 : 사분면 조각의 위치를 먼저 좌표로 구한후 x,y만큼 이동시킨 다음 다시 이를 사분면 위치로 바꿔주었다.
  • 이때 각각의 위치를 구하기 위해서 재귀를 사용하여 구하게 되었는데 해당 재귀를 만드는 과정에서 시간소요가 컸다

⏱️ 시간 복잡도

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

  • Big-O 표기법: O(n)
  • 이유: 각각의 함수는 size가 1이 될때까지 작동하는데 size의 크기는 2^n, 그리고 size/2만큼 줄어들기에 n의 시간 복잡도를 갖는다

💻 구현 코드

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

pair<ll, ll> get_Coordinate(string & point, int index, ll y, ll x, ll size) {
    if (size == 1) {
        return make_pair(x, y);
    }

    switch (point[index])
    {
    case '1':
        return get_Coordinate(point, index + 1, y, x + size / 2, size / 2);
    case '2':
        return get_Coordinate(point, index + 1, y, x, size / 2);
    case '3':
        return get_Coordinate(point, index + 1, y + size / 2, x , size / 2);
    case '4':
        return get_Coordinate(point, index + 1, y + size / 2, x + size / 2, size / 2);
    default:
        break;
    }
    return make_pair(0, 0);
}

string GetPoint(ll r, ll c, ll size, pair<ll, ll> point) {
    if (size == 1) {
        return "";
    }
    size /= 2;

    if (point.first < r + size && point.second < c + size) return "2" + GetPoint(r, c, size, point);
    else if (point.first < r + size && point.second >= c + size) return "3" + GetPoint(r, c + size, size, point);
    else if (point.first >= r + size && point.second < c + size) return "1" + GetPoint(r + size, c, size, point);
    else return "4" + GetPoint(r + size, c + size, size, point);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int d;
    string point;
    ll x, y;

    cin >> d >> point >> x >> y;

    ll size = 1LL << d;

    pair<ll, ll> p = get_Coordinate(point, 0, 0, 0, size);

    p.first += x;
    p.second -= y;


    if (0 <= p.first && p.first < size && 0 <= p.second && p.second < size)
        cout << GetPoint(0, 0, size, p);
    else cout << "-1" << "\n";

    return 0;
}

@esc10946 esc10946 linked an issue Jan 9, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

260109 : 코딩테스트

2 participants