[W01] DevJunz - SWEA 1문제 - #1
Conversation
내부 코어를 4방향 연결/포기하는 백트래킹으로 풀이. 연결 코어 수 최대화 후 전선 길이 최소화, can_go_dir로 방향 사전 가지치기. 5요소(접근/시간·공간 복잡도/핵심 풀이/코드) 정리.
📝 WalkthroughWalkthroughSWEA 1767 풀이 노트와 Python 백트래킹 구현을 추가했습니다. 내부 코어의 연결 방향을 탐색하고, 연결 코어 수와 전선 길이를 기준으로 최적해를 갱신합니다. Changes프로세서 연결하기 풀이
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/DevJunz/1767-프로세서연결하기.md`:
- Around line 24-28: 시간 복잡도 항목에서 DFS 비용만 제시하지 말고 입력 스캔 비용 O(N²)과 can_go_dir 전처리의
전체 코어 탐색 비용 O(K·C)를 포함하세요. 최종 전체 시간 복잡도를 O(N² + K·C + N·5^K)로 수정하고, 기존 분기별 DFS
설명은 유지하세요.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 0eb621db-b026-41d5-8f4f-77d1155bb1c5
📒 Files selected for processing (1)
studies/week-01/DevJunz/1767-프로세서연결하기.md
| ## 2. 시간 복잡도 | ||
| **O(N · 5^K)** — `K` = 내부 코어 수(최대 12), 각 코어에서 최대 5분기(4방향 + 연결 안 함). | ||
|
|
||
| - 각 분기에서 `check_path` / `set_path`가 전선을 격자 끝까지 훑으므로 분기당 `O(N)`. | ||
| - 따라서 최악 `O(N · 5^K)`. 다만 `can_go_dir` 사전 가지치기와 경로 충돌(`length == 0`) 덕분에 실제 탐색량은 이보다 크게 작다. `N ≤ 12`라 제한 시간 안에 통과. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
전체 시간 복잡도에 전처리 비용을 포함해 주세요.
현재 O(N · 5^K)는 DFS 탐색 비용만 설명합니다. 입력 스캔 O(N²)과 can_go_dir의 전체 코어 탐색 비용 O(K·C)(C = 전체 코어 수)가 누락되어, 전체 복잡도는 O(N² + K·C + N·5^K)로 적는 편이 정확합니다.
🤖 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/DevJunz/1767-프로세서연결하기.md` around lines 24 - 28, 시간 복잡도 항목에서
DFS 비용만 제시하지 말고 입력 스캔 비용 O(N²)과 can_go_dir 전처리의 전체 코어 탐색 비용 O(K·C)를 포함하세요. 최종 전체
시간 복잡도를 O(N² + K·C + N·5^K)로 수정하고, 기존 분기별 DFS 설명은 유지하세요.
|
@coderabbitai review |
✅ Action performedReview finished.
|
yeseoLee
left a comment
There was a problem hiding this comment.
1. any() 키워드 사용
하나라도 참이면 True 반환 -> 모두 틀리면 False 반환 -> flag False 없이 반복문 전부 통과한 것과 동일한 로직
core = []
for n in range(N):
for m in range(N):
if cells[n][m] == 1:
core.append((n,m))
target_core = []
for c in core:
# 벽에 붙어 있는 코어 스킵
if c[0]==0 or c[0]==N-1 or c[1]==0 or c[1]==N-1:
continue
# 0부터 3까지 상우하좌라고 가정한다.
can_go_dir = []
for i in range(4):
#하나의 코어당 다른 모든 코어에 대해서 검사해야한다
flag = True
for c2 in core:
#자기 자신은 스킵
if c == c2:
continue
#위로 이동하는 경우만 검사
if i == 0:
if c[1]==c2[1] and c[0]>c2[0]:
flag = False
break
elif i == 1:
if c[0]==c2[0] and c[1]<c2[1]:
flag = False
break
elif i == 2:
if c[1]==c2[1] and c[0]<c2[0]:
flag = False
break
elif i == 3:
if c[0]==c2[0] and c[1]>c2[1]:
flag = False
break
if flag:
can_go_dir.append(i)
# target_core 데이터 형태 (n좌표,m좌표,(이동가능한 방향 좌표))
target_core.append((c,tuple(can_go_dir)))core = [(n, m) for n in range(N) for m in range(N) if cells[n][m] == 1]
target_core = []
for r, c in core:
if r in (0, N-1) or c in (0, N-1):
continue
can_go_dir = []
if not any(c == c2 and r > r2 for r2, c2 in core):
can_go_dir.append(0) # 상
if not any(r == r2 and c < c2 for r2, c2 in core):
can_go_dir.append(1) # 우
if not any(c == c2 and r < r2 for r2, c2 in core):
can_go_dir.append(2) # 하
if not any(r == r2 and c > c2 for r2, c2 in core):
can_go_dir.append(3) # 좌
target_core.append(((r, c), tuple(can_go_dir)))2. 남은 코어 수를 활용한 가지치기
def dfs(idx, connected, total_length):
global max_core, min_length
# 현재 경로에서 달성할 수 있는 이론상 최대 코어 연결 수 계산
if connected + (len(target_core) - idx) < max_core:
return
if idx == len(target_core):
if connected>max_core:
max_core = connected
min_length = total_length
elif connected == max_core:
min_length = min(min_length,total_length)
return
📌 이번 PR 내용
✅ 푼 문제 (SWEA)
🧾 5요소 체크리스트
📋 규칙 체크
studies/week-01/DevJunz/1767-프로세서연결하기.md)💬 리뷰어에게
O(N·5^K)로 봤는데(4방향 + 연결 안 함), 타당한지 봐주세요.can_go_dir사전 가지치기 없이check_path만으로도 시간 내 통과하는지 궁금합니다.🧠 이번 주 회고 (한 줄)
백트래킹에서 "일부러 연결 안 하는" 선택지가 최댓값을 좌우한다는 걸 배움.
Summary by CodeRabbit