Skip to content

[W01] DevJunz - SWEA 1문제 - #1

Merged
DevJunz merged 2 commits into
mainfrom
week01/DevJunz
Jul 27, 2026
Merged

[W01] DevJunz - SWEA 1문제#1
DevJunz merged 2 commits into
mainfrom
week01/DevJunz

Conversation

@DevJunz

@DevJunz DevJunz commented Jul 23, 2026

Copy link
Copy Markdown
Owner

📌 이번 PR 내용

✅ 푼 문제 (SWEA)

번호 문제 링크
1767 프로세서 연결하기 https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV4suNtaXFEDFAUf

🧾 5요소 체크리스트

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

📋 규칙 체크

  • 파일 위치/이름 규칙 준수 (studies/week-01/DevJunz/1767-프로세서연결하기.md)
  • 커밋 메시지 템플릿 준수
  • 금요일 마감 전 제출

💬 리뷰어에게

  • 코드가 꽤 많이 긴데 어떻게 줄일 수 있을지 피드백 받고 싶습니다.
  • 시간복잡도 상한을 O(N·5^K)로 봤는데(4방향 + 연결 안 함), 타당한지 봐주세요.
  • can_go_dir 사전 가지치기 없이 check_path만으로도 시간 내 통과하는지 궁금합니다.

🧠 이번 주 회고 (한 줄)

백트래킹에서 "일부러 연결 안 하는" 선택지가 최댓값을 좌우한다는 걸 배움.

Summary by CodeRabbit

  • Documentation
    • Added a study note for SWEA 1767, “프로세서 연결하기.”
    • Documents the problem-solving strategy, including backtracking, pruning, path validation, and wire placement.
    • Includes a complete Python solution and a brief reflection on the approach.

내부 코어를 4방향 연결/포기하는 백트래킹으로 풀이.
연결 코어 수 최대화 후 전선 길이 최소화, can_go_dir로 방향 사전 가지치기.
5요소(접근/시간·공간 복잡도/핵심 풀이/코드) 정리.
@github-actions
github-actions Bot requested a review from yeseoLee July 23, 2026 15:59
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

SWEA 1767 풀이 노트와 Python 백트래킹 구현을 추가했습니다. 내부 코어의 연결 방향을 탐색하고, 연결 코어 수와 전선 길이를 기준으로 최적해를 갱신합니다.

Changes

프로세서 연결하기 풀이

Layer / File(s) Summary
문제 모델과 백트래킹 설계
studies/week-01/DevJunz/1767-프로세서연결하기.md
문제 목표, DFS 선택지, 복잡도, 경계 코어 제외, 방향 사전 계산, 전선 복구 및 우선순위 갱신 규칙을 정리합니다.
Python DFS 구현
studies/week-01/DevJunz/1767-프로세서연결하기.md
입력과 코어 목록을 구성하고, 경로 검사·배치 및 제거를 수행하며, 연결·건너뛰기 분기를 탐색해 결과를 출력합니다.

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

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive 제목이 SWEA 풀이 추가라는 점만 드러내고, 1767번과 핵심 변경 내용을 식별하기엔 너무 모호합니다. SWEA 1767 '프로세서 연결하기' 풀이 추가처럼 문제 번호와 핵심 내용을 드러내도록 수정하세요.
✅ Passed checks (4 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.
✨ 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/DevJunz

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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 5b5591a and 3bc5d3c.

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

Comment on lines +24 to +28
## 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`라 제한 시간 안에 통과.

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

전체 시간 복잡도에 전처리 비용을 포함해 주세요.

현재 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 설명은 유지하세요.

@DevJunz

DevJunz commented Jul 23, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@yeseoLee yeseoLee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

@DevJunz
DevJunz merged commit 3c9c474 into main Jul 27, 2026
1 check 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