solve: [W01] SWEA 1767 프로세서 연결하기 - #3
Conversation
📝 WalkthroughWalkthroughSWEA 1767 풀이 문서가 추가되었다. 가장자리 코어를 제외한 코어를 대상으로 DFS 백트래킹을 수행하며, 연결 코어 수 최대화 후 전선 길이 최소화 기준으로 최적 결과를 계산한다. Changes프로세서 연결 풀이
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
studies/week-01/min9u/1767-프로세서연결하기.md
| N×N 격자에서 값이 1인 칸이 '코어'이며, 이 중 가장자리(0행/0열/N-1행/N-1열)에 붙어 있는 코어는 이미 전원과 연결된 것으로 간주해 탐색 대상에서 제외한다. 나머지 코어들을 리스트로 모은 뒤, 각 코어마다 | ||
|
|
There was a problem hiding this comment.
🚀 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
| ## 2. 시간 복잡도 | ||
|
|
||
| **O(5^K × N)** — K는 가장자리가 아닌 코어의 개수(문제 제약상 N ≤ 12이므로 K도 그리 크지 않음), 5는 각 코어마다 "상/하/좌/우로 연결" 4가지 + "연결 안 함" 1가지의 선택지 수. 각 선택마다 해당 방향으로 장애물이 있는지 확인하고 그 경로를 채우고/비우는 데 O(N)이 걸리므로 여기에 N을 곱한다. 최악의 경우 5^K가 매우 커 보이지만, 실제로는 이미 막힌 방향은 가지치기되므로 체감 시간은 이보다 훨씬 짧다. |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
sed -n '1,220p' studies/week-01/min9u/1767-프로세서연결하기.mdRepository: 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:
- 1: https://velog.io/@clearsea/SWEA-1767.-%ED%94%84%EB%A1%9C%EC%84%B8%EC%84%9C-%EC%97%B0%EA%B2%B0%ED%95%98%EA%B8%B0-C
- 2: https://velog.io/@jeewoo1025/SWEA-%ED%94%84%EB%A1%9C%EC%84%B8%EC%84%9C-%EC%97%B0%EA%B2%B0%ED%95%98%EA%B8%B0
- 3: https://so-cute-danu-dev.tistory.com/9
- 4: https://bellbpng.github.io/samsung%20sw/processor/
- 5: https://velog.io/@yunhlim/SWEA-1767.-SW-Test-%EC%83%98%ED%94%8C%EB%AC%B8%EC%A0%9C-%ED%94%84%EB%A1%9C%EC%84%B8%EC%84%9C-%EC%97%B0%EA%B2%B0%ED%95%98%EA%B8%B0
- 6: https://goodgid.github.io/SWEA-1767/
시간 복잡도 표기를 코드에 맞게 고치세요.
지금 구현은 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
| ## 3. 공간 복잡도 | ||
|
|
||
| **O(N²)** — 코어/전선 상태를 저장하는 tile 2차원 배열이 N×N 크기이며, 코어 좌표 리스트(cores)는 최대 N² 개까지 저장될 수 있으나 실제로는 그보다 훨씬 작다. 재귀 호출 스택의 깊이는 O(K) 수준으로 N²에 비해 무시할 만하다. |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win
공간 복잡도의 근거를 정확히 표현하세요.
tile은 O(N²), cores와 재귀 스택은 각각 O(K)이므로 전체는 O(N² + K) = O(N²)입니다. 최종 결론은 맞지만, 현재 코드 기준 K가 O(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
| 헤맸던 포인트 : "최대한 많은 코어"에 전원을 연결하였을 경우, 전설 길이의 합이 최소가 되는 값을 구하라 | ||
| 코어가 다 연결되지 않는 경우를 생각하지 않았음. 문제 조건을 더 자세히 살펴볼것 | ||
| ''' |
There was a problem hiding this comment.
📐 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
| 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 |
There was a problem hiding this comment.
🚀 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 -nRepository: 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.
| 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
left a comment
There was a problem hiding this comment.
실제 코테 문제를 풀다보면
코드를 함수화해서 일반화하는 것보다 지금 작성하신 것 처럼
각 경우마다(지금 코드에서는 상하좌우) 에 대해서 전부 검사하는 코드를 쓰는게 더 빠른 것 같아요(ctrl + c, ctrl +v로 하면 일반화 함수 작성하는 것 보다 더 빨라서...)
그래도 연습을 위해서 하나의 함수로 확인 하는 방법도 해보면 좋을 것 같습니다.
📌 이번 PR 내용
✅ 푼 문제 (SWEA)
🧾 5요소 체크리스트
각 풀이에 아래 5요소를 모두 작성했는지 확인합니다.
📋 규칙 체크
studies/week-XX/<깃허브ID>/<문제번호>-<문제이름>.md)💬 리뷰어에게
🧠 이번 주 회고 (한 줄)
Summary by CodeRabbit