Skip to content

Conversation

@alirz-pixel
Copy link
Member

🚀 이슈 번호

Resolve: {#2293}

🧩 문제 해결

스스로 해결:

🔎 접근 과정

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

  • 🔹 어떤 알고리즘을 사용했는지: 수학 + 분할정복
  • 🔹 어떤 방식으로 접근했는지

입력으로 주어지는 d에 대하여 $2^{d-1}$ 꼴의 좌표평면으로 교체한다.

이후 step을 $2^{d-1}$부터 출발하여 2로 나누어가며 다음의 규칙을 적용한다.

  • 1사분면: step / 2의 값을 x에는 더하고 y에도 더한다.
  • 2사분면: step / 2의 값을 x에는 빼고 y에는 더한다.
  • 3사분면: step / 2의 값을 x에는 빼고 y에도 뺀다.
  • 4사분면: step / 2의 값을 x에는 더하고 y에는 뺀다.

이렇게하면 입력으로 주어진 사분면 조각에 따른 좌표로 교체가 가능하다.
이를 활용하여 각 좌표에 x , y를 더해주면 된다.

(조각 번호는 이 과정을 반대로 해주면 된다.)

⏱️ 시간 복잡도

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

  • Big-O 표기법: O(d)
  • 이유: 사분면 조각을 구하기 위해 d 만큼의 연산만 수행되기 때문이다.

💻 구현 코드

#include <iostream>
#include <math.h>

using namespace std;

struct Coord {
	long double y;
	long double x;
};

int main() {
	long long d;  string shape;
	long long x, y;
	cin >> d >> shape;
	cin >> x >> y;

	long double boundary = powl(2, d - 1);
	long double step = powl(2, d - 1);

	struct Coord cur = { 0, 0 };
	for (auto c : shape) {
		if (c == '1') {
			cur.x += step / 2;
			cur.y += step / 2;
		}
		else if (c == '2') {
			cur.x -= step / 2;
			cur.y += step / 2;
		}
		else if (c == '3') {
			cur.x -= step / 2;
			cur.y -= step / 2;
		}
		else {
			cur.x += step / 2;
			cur.y -= step / 2;
		}

		step /= 2;
	}
	cur.x += x;
	cur.y += y;
	if (boundary < abs(cur.y) || boundary < abs(cur.x)) {
		cout << -1;
		return 0;
	}

	string answer = "";
	step = powl(2, d - 1);
	Coord point = { 0, 0 };
	for (int i = 0; i < d; i++) {
		if (point.y < cur.y && point.x < cur.x) { // 1 사분면
			point.x += step / 2;
			point.y += step / 2;
			answer += "1";
		}
		else if (point.y < cur.y && point.x > cur.x) { // 2 사분면
			point.x -= step / 2;
			point.y += step / 2;
			answer += "2";
		}
		else if (point.y > cur.y && point.x > cur.x) { // 3 사분면
			point.x -= step / 2;
			point.y -= step / 2;
			answer += "3";
		}
		else { // 4 사분면
			point.x += step / 2;
			point.y -= step / 2;
			answer += "4";
		}

		step /= 2;
	}

	cout << answer;

	return 0;
}

@alirz-pixel alirz-pixel self-assigned this Jan 9, 2026
@alirz-pixel alirz-pixel linked an issue Jan 9, 2026 that may be closed by this pull request
@alirz-pixel alirz-pixel merged commit ceecd03 into main Jan 12, 2026
1 check passed
@alirz-pixel alirz-pixel deleted the munhyeong/2293/1 branch January 12, 2026 16:57
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.

260109 : 코딩테스트

2 participants