Skip to content

solve: [W01] SWEA 1767 프로세서 연결하기 - #3

Merged
min9u merged 1 commit into
mainfrom
week01/min9u
Jul 27, 2026
Merged

solve: [W01] SWEA 1767 프로세서 연결하기#3
min9u merged 1 commit into
mainfrom
week01/min9u

Conversation

@min9u

@min9u min9u commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

📌 이번 PR 내용

  • 주차: W01
  • 작성자: @min9u

✅ 푼 문제 (SWEA)

번호 문제 링크
1 1767 https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV4suNtaXFEDFAUf&categoryId=AV4suNtaXFEDFAUf&categoryType=CODE&problemTitle=1767&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=&pageSize=10&pageIndex=1

🧾 5요소 체크리스트

각 풀이에 아래 5요소를 모두 작성했는지 확인합니다.

  • 1. 접근 방법
  • 2. 시간 복잡도
  • 3. 공간 복잡도
  • 4. 핵심 풀이 방법
  • 5. 실제 코드

📋 규칙 체크

  • 파일 위치/이름 규칙 준수 (studies/week-XX/<깃허브ID>/<문제번호>-<문제이름>.md)
  • 커밋 메시지 템플릿 준수
  • 가능하면 문제를 푼 날(월~목)에 맞춰 그날그날 PR 제출 (놓쳤다면 나중에 몰아서 제출해도 OK)
  • 금요일 마감 전 제출 (해당 주 일정 확인)

💬 리뷰어에게

🧠 이번 주 회고 (한 줄)

Summary by CodeRabbit

  • 문서
    • SWEA 1767 ‘프로세서 연결하기’ 문제의 풀이 문서를 추가했습니다.
    • 완전탐색과 백트래킹을 활용한 접근 방식, 연결 우선순위 및 전선 길이 최소화 기준을 설명합니다.
    • 시간·공간 복잡도와 풀이 과정에서의 주요 고려사항을 함께 정리했습니다.

@github-actions
github-actions Bot requested a review from DevJunz July 24, 2026 05:44
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

SWEA 1767 풀이 문서가 추가되었다. 가장자리 코어를 제외한 코어를 대상으로 DFS 백트래킹을 수행하며, 연결 코어 수 최대화 후 전선 길이 최소화 기준으로 최적 결과를 계산한다.

Changes

프로세서 연결 풀이

Layer / File(s) Summary
탐색 전략과 평가 기준
studies/week-01/min9u/1767-프로세서연결하기.md
가장자리 코어를 제외하고 각 코어에 네 방향 연결 또는 미연결을 선택하는 DFS 전략과, 연결 코어 수 우선·전선 길이 차선의 평가 기준을 설명한다.
DFS 백트래킹 구현과 회고
studies/week-01/min9u/1767-프로세서연결하기.md
경로 충돌 검사, 전선 표시 및 복구, 전역 최적값 갱신, 결과 출력을 포함한 파이썬 구현과 풀이 회고를 기록한다.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목이 SWEA 1767 프로세서 연결하기 풀이 추가라는 핵심 변경을 간결하게 잘 요약합니다.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch week01/min9u

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@studies/week-01/min9u/1767-프로세서연결하기.md`:
- Around line 44-46: 회고 주석의 “전설 길이” 오타를 “전선 길이”로 수정하고, 해당 문장이 자연스럽고 읽기 쉽게 유지되는지
확인하세요.
- Around line 28-30: 공간 복잡도 절의 근거를 실제 자료구조 기준으로 수정하세요. tile은 O(N²), cores와 재귀 호출
스택은 각각 O(K)로 명시하고, 전체 공간 복잡도를 O(N² + K) = O(N²)로 정리하세요. K가 O(N²)일 수 있으므로 재귀 스택을
무시할 수 있다는 설명은 제거하세요.
- Around line 15-16: 경계 코어 제외 조건이 설명과 구현에서 일치하도록 수정하세요.
studies/week-01/min9u/1767-프로세서연결하기.md의 15-16행 설명은 내부 코어만 탐색 대상으로 삼는 동작을 명확히
유지하고, 52-56행의 코어 수집 로직은 0 < i < n - 1 및 0 < j < n - 1 조건을 적용해 내부 코어만 리스트에 추가하도록
변경하세요.
- Around line 65-73: Update the DFS function to return immediately when core +
(len(cores) - idx) < max_core, placing this upper-bound pruning before deeper
exploration. Use a strict less-than comparison so branches that can still tie
max_core remain available for min_score comparison.
- Around line 24-26: 시간 복잡도 설명을 DFS 구현의 실제 대상인 전체 코어 수 C = len(cores)에 맞춰 O(5^C
× N)으로 수정하세요. 가장자리 코어도 cores에 포함되어 처리된다는 점을 반영하고, N ≤ 12를 근거로 내부 코어 K가 작다고 설명하지
마세요. 코어 수 상한 12에서 최악의 경우 TLE 위험을 명시하고, 가능하면 남은 코어 수를 이용한 상한 가지치기 적용도 설명에 추가하세요.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f8990f41-a1a5-4adb-9f0d-4ead87a62347

📥 Commits

Reviewing files that changed from the base of the PR and between 5b5591a and 2a2eab1.

📒 Files selected for processing (1)
  • studies/week-01/min9u/1767-프로세서연결하기.md

Comment on lines +15 to +16
N×N 격자에서 값이 1인 칸이 '코어'이며, 이 중 가장자리(0행/0열/N-1행/N-1열)에 붙어 있는 코어는 이미 전원과 연결된 것으로 간주해 탐색 대상에서 제외한다. 나머지 코어들을 리스트로 모은 뒤, 각 코어마다

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

경계 코어 제외 조건을 문서와 코드에 일관되게 적용하세요.

문서는 경계 코어를 제외한다고 설명하지만, 구현은 모든 코어를 DFS에 넣어 불필요한 방향 분기를 생성합니다.

  • studies/week-01/min9u/1767-프로세서연결하기.md#L15-L16: 접근 설명과 실제 구현의 조건을 일치시키세요.
  • studies/week-01/min9u/1767-프로세서연결하기.md#L52-L56: 0 < i < n - 1 and 0 < j < n - 1 조건으로 내부 코어만 수집하세요.

As per path instructions, studies/**/*.md에서는 문서와 실제 코드의 로직 일치 여부 및 최대 입력의 성능 위험을 검증해야 합니다.

📍 Affects 1 file
  • studies/week-01/min9u/1767-프로세서연결하기.md#L15-L16 (this comment)
  • studies/week-01/min9u/1767-프로세서연결하기.md#L52-L56
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@studies/week-01/min9u/1767-프로세서연결하기.md` around lines 15 - 16, 경계 코어 제외 조건이
설명과 구현에서 일치하도록 수정하세요. studies/week-01/min9u/1767-프로세서연결하기.md의 15-16행 설명은 내부 코어만
탐색 대상으로 삼는 동작을 명확히 유지하고, 52-56행의 코어 수집 로직은 0 < i < n - 1 및 0 < j < n - 1 조건을 적용해
내부 코어만 리스트에 추가하도록 변경하세요.

Source: Path instructions

Comment on lines +24 to +26
## 2. 시간 복잡도

**O(5^K × N)** — K는 가장자리가 아닌 코어의 개수(문제 제약상 N ≤ 12이므로 K도 그리 크지 않음), 5는 각 코어마다 "상/하/좌/우로 연결" 4가지 + "연결 안 함" 1가지의 선택지 수. 각 선택마다 해당 방향으로 장애물이 있는지 확인하고 그 경로를 채우고/비우는 데 O(N)이 걸리므로 여기에 N을 곱한다. 최악의 경우 5^K가 매우 커 보이지만, 실제로는 이미 막힌 방향은 가지치기되므로 체감 시간은 이보다 훨씬 짧다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

sed -n '1,220p' studies/week-01/min9u/1767-프로세서연결하기.md

Repository: DevJunz/coding-test-study-template

Length of output: 5543


🌐 Web query:

SWEA 1767 프로세서 연결하기 constraints core count N <= 12 maximum cores

💡 Result:

The constraints for the SW Expert Academy (SWEA) problem 1767, "Processor Connection" (프로세서 연결하기), are as follows: - Grid Size (N): 7 <= N <= 12 [1][2][3] - Number of Cores: The number of cores is between 1 and 12 [1][3]. The goal of the problem is to connect as many cores as possible to the power source located at the edge of the grid [4][5]. When multiple ways exist to connect the maximum number of cores, the solution must choose the one with the minimum total wire length [3][5]. Cores already located on the edge are considered connected to the power source by default [4][6][5].

Citations:


시간 복잡도 표기를 코드에 맞게 고치세요.
지금 구현은 cores에 가장자리 코어까지 모두 넣어서 DFS를 돌리므로, 실제 깊이는 내부 코어 K가 아니라 전체 코어 수 C = len(cores)입니다. 따라서 이 코드의 최악 복잡도는 O(5^C × N)이고, 설명처럼 N ≤ 12라서 K가 작다는 근거도 맞지 않습니다. 문제의 코어 수 상한은 12이므로, 최악 입력 기준 TLE 위험도 같이 적고 남은 코어 수로 상한 가지치기 같은 pruning을 덧붙이는 게 좋습니다.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@studies/week-01/min9u/1767-프로세서연결하기.md` around lines 24 - 26, 시간 복잡도 설명을 DFS
구현의 실제 대상인 전체 코어 수 C = len(cores)에 맞춰 O(5^C × N)으로 수정하세요. 가장자리 코어도 cores에 포함되어
처리된다는 점을 반영하고, N ≤ 12를 근거로 내부 코어 K가 작다고 설명하지 마세요. 코어 수 상한 12에서 최악의 경우 TLE 위험을
명시하고, 가능하면 남은 코어 수를 이용한 상한 가지치기 적용도 설명에 추가하세요.

Source: Path instructions

Comment on lines +28 to +30
## 3. 공간 복잡도

**O(N²)** — 코어/전선 상태를 저장하는 tile 2차원 배열이 N×N 크기이며, 코어 좌표 리스트(cores)는 최대 N² 개까지 저장될 수 있으나 실제로는 그보다 훨씬 작다. 재귀 호출 스택의 깊이는 O(K) 수준으로 N²에 비해 무시할 만하다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

공간 복잡도의 근거를 정확히 표현하세요.

tileO(N²), cores와 재귀 스택은 각각 O(K)이므로 전체는 O(N² + K) = O(N²)입니다. 최종 결론은 맞지만, 현재 코드 기준 KO(N²)일 수 있으므로 재귀 스택을 “무시할 만하다”고 설명하는 것은 부정확합니다.

As per path instructions, studies/**/*.md에서는 공간 복잡도를 실제 자료구조와 재귀 깊이 기준으로 검증해야 합니다.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@studies/week-01/min9u/1767-프로세서연결하기.md` around lines 28 - 30, 공간 복잡도 절의 근거를
실제 자료구조 기준으로 수정하세요. tile은 O(N²), cores와 재귀 호출 스택은 각각 O(K)로 명시하고, 전체 공간 복잡도를 O(N²
+ K) = O(N²)로 정리하세요. K가 O(N²)일 수 있으므로 재귀 스택을 무시할 수 있다는 설명은 제거하세요.

Source: Path instructions

Comment on lines +44 to +46
헤맸던 포인트 : "최대한 많은 코어"에 전원을 연결하였을 경우, 전설 길이의 합이 최소가 되는 값을 구하라
코어가 다 연결되지 않는 경우를 생각하지 않았음. 문제 조건을 더 자세히 살펴볼것
'''

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

회고 주석의 오타를 수정하세요.

전설 길이전선 길이로 고쳐야 문서 의미가 정확합니다.

As per path instructions, 사용자에게 보이는 문서의 문장 품질과 가독성도 점검해야 합니다.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@studies/week-01/min9u/1767-프로세서연결하기.md` around lines 44 - 46, 회고 주석의 “전설 길이”
오타를 “전선 길이”로 수정하고, 해당 문장이 자연스럽고 읽기 쉽게 유지되는지 확인하세요.

Source: Path instructions

Comment on lines +65 to +73
def dfs():
global idx, score, min_score, max_core, core
if core==max_core:
min_score = min(min_score, score)
if core>max_core:
min_score = score
max_core = core
if idx == len(cores):
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

file='studies/week-01/min9u/1767-프로세서연결하기.md'

# 기본 구조와 코드 위치 확인
wc -l "$file"
rg -n "def dfs|max_core|min_score|core|시간 복잡도|공간 복잡도|접근|핵심 풀이|실제 코드" "$file"

# 관련 구간만 번호와 함께 확인
sed -n '1,220p' "$file" | cat -n

Repository: DevJunz/coding-test-study-template

Length of output: 8278


남은 코어 수 상한으로 DFS를 가지치기하세요.
core + (len(cores) - idx) < max_core 인 가지는 남은 코어를 전부 연결해도 현재 최댓값을 넘지 못하므로 바로 반환하면 됩니다. 같은 max_core를 만들 수 있는 가지는 남겨 둬야 전선 길이 최소값 비교가 유지됩니다.

수정안
         if idx == len(cores):
             return
+        if core + (len(cores) - idx) < max_core:
+            return
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def dfs():
global idx, score, min_score, max_core, core
if core==max_core:
min_score = min(min_score, score)
if core>max_core:
min_score = score
max_core = core
if idx == len(cores):
return
def dfs():
global idx, score, min_score, max_core, core
if core==max_core:
min_score = min(min_score, score)
if core>max_core:
min_score = score
max_core = core
if idx == len(cores):
return
if core + (len(cores) - idx) < max_core:
return
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@studies/week-01/min9u/1767-프로세서연결하기.md` around lines 65 - 73, Update the DFS
function to return immediately when core + (len(cores) - idx) < max_core,
placing this upper-bound pruning before deeper exploration. Use a strict
less-than comparison so branches that can still tie max_core remain available
for min_score comparison.

Source: Path instructions

@DevJunz DevJunz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

실제 코테 문제를 풀다보면
코드를 함수화해서 일반화하는 것보다 지금 작성하신 것 처럼
각 경우마다(지금 코드에서는 상하좌우) 에 대해서 전부 검사하는 코드를 쓰는게 더 빠른 것 같아요(ctrl + c, ctrl +v로 하면 일반화 함수 작성하는 것 보다 더 빨라서...)
그래도 연습을 위해서 하나의 함수로 확인 하는 방법도 해보면 좋을 것 같습니다.

@min9u
min9u merged commit 31a80c1 into main Jul 27, 2026
2 checks passed
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.

2 participants