Skip to content

solve: [W02] SWEA 26070, 26071, 5656, 5658 - #9

Open
clarityth wants to merge 7 commits into
mainfrom
week02/clarityth
Open

solve: [W02] SWEA 26070, 26071, 5656, 5658#9
clarityth wants to merge 7 commits into
mainfrom
week02/clarityth

Conversation

@clarityth

@clarityth clarityth commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

📌 이번 PR 내용

✅ 푼 문제 (SWEA)

번호 문제 링크
5658 보물상자 비밀번호 https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRUN9KfZ8DFAUo
5656 벽돌 깨기 https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRQm6qfL0DFAUo
26071 블록 제거 게임 https://swexpertacademy.com/main/code/userProblem/userProblemDetail.do?contestProbId=AZwmCVWq3uLHBIT3
26070 보석 수집 로봇 https://swexpertacademy.com/main/code/userProblem/userProblemDetail.do?contestProbId=AZwmBfua3q3HBIT3

🧾 5요소 체크리스트

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

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

📋 규칙 체크

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

💬 리뷰어에게

혹시 다른 방법으로 해결하신 문제가 있다면 어떻게 푸셨는지 궁금합니다.

🧠 이번 주 회고 (한 줄)

문제들이 생각보다 쉽지 않아서 더 많은 문제 유형을 풀어봐야겠다고 생각했습니다.

Summary by CodeRabbit

  • 문서화
    • SWEA ‘보석 수집 로봇’, ‘블록 제거 게임’, ‘벽돌깨기’, ‘보물상자 비밀번호’ 문제의 풀이 문서를 추가했습니다.
    • 각 문서에 문제 접근 방법, 알고리즘, 복잡도, Python 구현 코드와 회고를 포함했습니다.
    • 다익스트라, 구간 DP, DFS 백트래킹, 회전 및 16진수 변환 풀이를 정리했습니다.

@github-actions
github-actions Bot requested a review from DevJunz July 30, 2026 15:19
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

SWEA 26070, 26071, 5656, 5658의 문제 메타정보, 알고리즘 풀이 설명, 복잡도 분석, Python 구현 및 회고 문서가 추가되었다.

Changes

보물 수집 로봇 풀이

Layer / File(s) Summary
상태 확장 다익스트라 구현
studies/week-02/clarityth/26070-보석수집로봇.md
방향·위치·다음 목표 보석을 상태로 관리하고, 보석 획득·우회전·직진 전이를 다익스트라로 처리하는 풀이와 구현을 추가했다.

블록 제거 게임 풀이

Layer / File(s) Summary
구간 DP와 점수 전이
studies/week-02/clarityth/26071-블록제거게임.md
마지막 제거 블록을 기준으로 구간을 분할하고, 경계 이웃 점수를 반영하는 Top-Down 메모이제이션 구현과 복잡도 설명을 추가했다.

벽돌 깨기 풀이

Layer / File(s) Summary
DFS 시뮬레이션 구현
studies/week-02/clarityth/5656-벽돌깨기.md
구슬 투하 열을 DFS로 선택하고, 재귀 연쇄 폭발과 열 단위 중력을 수행하며 남은 벽돌 최솟값을 갱신하는 풀이를 추가했다.

보물상자 비밀번호 풀이

Layer / File(s) Summary
회전 조각 추출과 진법 변환
studies/week-02/clarityth/5658-보물상자비밀번호.md
문자열을 N/4 단위로 회전하며 중복 없는 16진수 조각을 수집하고, 내림차순 K번째 값을 10진수로 변환하는 풀이와 구현을 추가했다.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: devjunz

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed SWEA 26070, 26071, 5656, 5658 풀이 추가라는 변경사항을 직접적으로 요약해 제목이 본문과 잘 맞습니다.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch week02/clarityth

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

@clarityth clarityth changed the title solve: [W02] SWEA 5656, 5658, 26070, 26071 solve: [W02] SWEA 26070, 26071, 5656, 5658 Jul 30, 2026

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

🤖 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-02/clarityth/26070-보석수집로봇.md`:
- Around line 7-13: 문서 제목과 문제 링크 식별자를 실제 대상인 SWEA 26070에 맞게 수정하고, 주제 항목의 오타인
“Djikstra”를 “Dijkstra”로 바로잡으세요. 기존 문서의 메타데이터 형식과 나머지 내용은 유지하세요.
- Around line 26-31: Update the “2. 시간 복잡도” section to account for up to three
transitions per state, expressing E ≤ 3V and the per-test-case complexity as
O((V + E) log V) = O(N² · M · log(N² · M)). Include the total T test cases in
the overall complexity, and remove the unsupported claim that approximately 4000
log 4000 guarantees completion within 0.01 seconds.

In `@studies/week-02/clarityth/5656-벽돌깨기.md`:
- Line 135: 파일 끝을 정리하여 마지막 문자 뒤에 정확히 하나의 개행만 남기고, 추가 공백이나 빈 줄은 제거하세요.
- Around line 31-34: 시간 복잡도 설명에서 리프 수 20,736에 기반한 “약 370만 연산” 수치를 제거하거나,
W=12·N=4일 때 실제 DFS 간선 수인 W + W² + W³ + W⁴ = 22,620을 사용해 상한을 다시 계산하세요. 점근식 O(W^N
· H · W)과 보드 복사·폭발·중력이 각 DFS 간선에서 수행된다는 설명은 유지하세요.
- Around line 51-52: 중력 정렬 설명을 실제 구현에 맞게 수정하세요. 각 열을 위에서 아래로 순회하며 0이 아닌 벽돌을
temp에 모은 뒤 pop()으로 아래 칸부터 채우는 흐름을 명시하고, 기존의 “아래에서부터 수집” 표현은 제거하세요.

In `@studies/week-02/clarityth/5658-보물상자비밀번호.md`:
- Around line 59-79: Update the rotation extraction logic around rotated_nums to
convert each hexadecimal segment with int(part, 16) before inserting it into the
collection, so deduplication and descending sorting operate on integers. Replace
the string-based set and remove the now-unnecessary hex_to_decimal function,
then use the selected integer directly in the final output while preserving the
K-th largest result.
- Around line 26-39: 문서의 시간·공간 복잡도 근거를 실제 회전, 조각 추출, 정렬, set 저장 동작에 맞게 수정하세요. 시간
복잡도는 회전 및 추출 O(N²), 문자열 비교 비용을 포함한 정렬 최악 O(N² log N), 16진수 변환 O(N)으로 설명하고 최종값은
O(N² log N)으로 유지하세요. 길이 N/4 문자열을 최대 N개 저장하는 set 때문에 공간 복잡도는 O(N²)로 수정하고, sorted
리스트의 참조 공간 O(N)은 지배적이지 않음을 명시하세요.
🪄 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: 2ca98480-7b9e-4e33-9aaa-24031b9285d6

📥 Commits

Reviewing files that changed from the base of the PR and between 31a80c1 and b2f16a5.

📒 Files selected for processing (4)
  • studies/week-02/clarityth/26070-보석수집로봇.md
  • studies/week-02/clarityth/26071-블록제거게임.md
  • studies/week-02/clarityth/5656-벽돌깨기.md
  • studies/week-02/clarityth/5658-보물상자비밀번호.md

Comment thread studies/week-02/clarityth/26070-보석수집로봇.md Outdated
Comment thread studies/week-02/clarityth/26070-보석수집로봇.md Outdated
Comment thread studies/week-02/clarityth/5656-벽돌깨기.md Outdated
Comment thread studies/week-02/clarityth/5656-벽돌깨기.md Outdated
Comment thread studies/week-02/clarityth/5656-벽돌깨기.md Outdated
Comment thread studies/week-02/clarityth/5658-보물상자비밀번호.md Outdated
Comment on lines +59 to +79
rotated_nums = set()
for i in range(N // 4):
rotate_str = (input_str[-i:] + input_str[:-i])
for j in range(0, len(rotate_str), N // 4):
rotated_nums.add(rotate_str[j : j + N // 4])

sorted_rotated_nums = sorted(list(rotated_nums), reverse=True)

def hex_to_decimal(hex_str):
ans = 0
offset = 1
for i in range(len(hex_str) - 1, -1, -1):
c = hex_str[i]
if c.isdigit():
ans += int(c) * offset
elif c.isalpha():
ans += ((ord(c) - ord('A')) + 10) * offset
offset *= 16
return ans

print(f"#{test_case} {hex_to_decimal(sorted_rotated_nums[K-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.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

16진수 조각을 정수로 직접 저장하면 구현과 메모리를 줄일 수 있습니다.

현재는 문자열을 set에 저장한 뒤 별도의 변환 함수를 호출합니다. int(part, 16)을 추출 시점에 사용하면 정렬도 정수 기준으로 수행되고, 저장 공간을 O(N²)에서 O(N)으로 줄일 수 있습니다.

경로 지침의 “통과한 코드라도 더 간결하거나 관용적인 구현이 있으면 대안 코드로 제안” 항목에 따른 선택적 개선입니다.

대안 코드
     rotated_nums = set()
     for i in range(N // 4):
         rotate_str = (input_str[-i:] + input_str[:-i])
         for j in range(0, len(rotate_str), N // 4):
-            rotated_nums.add(rotate_str[j : j + N // 4])
+            part = rotate_str[j : j + N // 4]
+            rotated_nums.add(int(part, 16))

-    sorted_rotated_nums = sorted(list(rotated_nums), reverse=True)
-
-    def hex_to_decimal(hex_str):
-        ...
-        return ans
+    sorted_rotated_nums = sorted(rotated_nums, reverse=True)

-    print(f"#{test_case} {hex_to_decimal(sorted_rotated_nums[K-1])}")
+    print(f"#{test_case} {sorted_rotated_nums[K-1]}")
📝 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
rotated_nums = set()
for i in range(N // 4):
rotate_str = (input_str[-i:] + input_str[:-i])
for j in range(0, len(rotate_str), N // 4):
rotated_nums.add(rotate_str[j : j + N // 4])
sorted_rotated_nums = sorted(list(rotated_nums), reverse=True)
def hex_to_decimal(hex_str):
ans = 0
offset = 1
for i in range(len(hex_str) - 1, -1, -1):
c = hex_str[i]
if c.isdigit():
ans += int(c) * offset
elif c.isalpha():
ans += ((ord(c) - ord('A')) + 10) * offset
offset *= 16
return ans
print(f"#{test_case} {hex_to_decimal(sorted_rotated_nums[K-1])}")
rotated_nums = set()
for i in range(N // 4):
rotate_str = (input_str[-i:] + input_str[:-i])
for j in range(0, len(rotate_str), N // 4):
part = rotate_str[j : j + N // 4]
rotated_nums.add(int(part, 16))
sorted_rotated_nums = sorted(rotated_nums, reverse=True)
print(f"#{test_case} {sorted_rotated_nums[K-1]}")
🤖 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-02/clarityth/5658-보물상자비밀번호.md` around lines 59 - 79, Update the
rotation extraction logic around rotated_nums to convert each hexadecimal
segment with int(part, 16) before inserting it into the collection, so
deduplication and descending sorting operate on integers. Replace the
string-based set and remove the now-unnecessary hex_to_decimal function, then
use the selected integer directly in the final output while preserving the K-th
largest result.

Source: Path instructions

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
studies/week-02/clarityth/26070-보석수집로봇.md (1)

55-120: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

0-1 BFS를 고려해 보세요.

보석 획득·직진 전이는 비용 0이고 우회전 전이는 비용 1이므로 0-1 BFS를 사용하면 케이스당 O(V + E) = O(N² · M)으로 개선할 수 있습니다. 현재 Dijkstra도 최대 상태 수에서는 TLE 위험이 낮지만, 우선순위 큐와 log V 비용은 불필요합니다. 변경 시 2번 시간 복잡도도 함께 갱신하세요.

🤖 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-02/clarityth/26070-보석수집로봇.md` around lines 55 - 120, Replace the
Dijkstra priority-queue traversal around dist and pq with 0-1 BFS using a deque:
append zero-cost jewel-acquisition and forward-movement transitions to the
front, and append the cost-1 right-rotation transition to the back. Preserve the
existing state model, transition behavior, and earliest-completion logic, and
update the documented time complexity in section 2 to O(N² · M) per test case.

Source: Path instructions

studies/week-02/clarityth/5656-벽돌깨기.md (2)

39-41: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

boom 재귀 스택을 공간 복잡도에 포함해 주세요.

최종 복잡도 O(N·H·W)는 맞지만, boom의 연쇄 폭발 재귀 깊이가 최대 H·W라는 근거가 빠져 있습니다. DFS 보드 복사 O(N·H·W)와 폭발 재귀 스택 O(H·W)를 함께 적어 O(N·H·W + H·W) = O(N·H·W)로 설명해 주세요.

As per path instructions: 공간 복잡도는 실제 코드의 재귀 및 자료구조 사용량을 직접 계산해야 합니다.

수정 예시
 * **재귀 호출 스택**: DFS 깊이 최대 $N$개.
+* **연쇄 폭발 재귀 스택**: `boom` 호출 깊이 최대 $H \times W$개.
 * **보드 복사**: 매 재귀 단계마다 $H \times W$크기의 `next_board` deepcopy ($N \times H \times W$).
🤖 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-02/clarityth/5656-벽돌깨기.md` around lines 39 - 41, 공간 복잡도 설명에서
`boom`의 연쇄 폭발 재귀 스택을 별도로 계산하세요. DFS 보드 복사 공간 `O(N·H·W)`에 `boom` 재귀 깊이 최대
`O(H·W)`를 더해 `O(N·H·W + H·W) = O(N·H·W)`로 정리하고, 해당 근거를 재귀 및 자료구조 사용량에 맞게 명시하세요.

Source: Path instructions


116-123: 🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

ans == 0을 형제 분기에도 전파해 조기 종료를 완성하세요.

현재 검사는 자식 dfs 진입 시점에만 수행됩니다. 한 분기에서 ans == 0이 되어 돌아와도 부모의 for col이 남은 열을 계속 처리하므로, 최대 입력에서 불필요한 보드 복사·폭발·중력 연산이 반복됩니다. 열 순회 시작 전에 종료 조건을 추가하세요.

As per path instructions: SWEA는 시간 제한이 빡빡하므로 입력 최대치에서 불필요한 분기와 연산을 줄여야 합니다.

수정 예시
        for col in range(W):
+            if ans == 0:
+                return
            for row in range(H):
🤖 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-02/clarityth/5656-벽돌깨기.md` around lines 116 - 123, Update the
DFS column-iteration logic around the nested `for col` and `for row` loops to
check `ans == 0` before starting each new column branch, returning immediately
when the optimum is reached. Preserve the existing child `dfs` behavior and
board-processing logic for cases where `ans` is not yet zero.

Source: Path instructions

🤖 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.

Outside diff comments:
In `@studies/week-02/clarityth/26070-보석수집로봇.md`:
- Around line 55-120: Replace the Dijkstra priority-queue traversal around dist
and pq with 0-1 BFS using a deque: append zero-cost jewel-acquisition and
forward-movement transitions to the front, and append the cost-1 right-rotation
transition to the back. Preserve the existing state model, transition behavior,
and earliest-completion logic, and update the documented time complexity in
section 2 to O(N² · M) per test case.

In `@studies/week-02/clarityth/5656-벽돌깨기.md`:
- Around line 39-41: 공간 복잡도 설명에서 `boom`의 연쇄 폭발 재귀 스택을 별도로 계산하세요. DFS 보드 복사 공간
`O(N·H·W)`에 `boom` 재귀 깊이 최대 `O(H·W)`를 더해 `O(N·H·W + H·W) = O(N·H·W)`로 정리하고, 해당
근거를 재귀 및 자료구조 사용량에 맞게 명시하세요.
- Around line 116-123: Update the DFS column-iteration logic around the nested
`for col` and `for row` loops to check `ans == 0` before starting each new
column branch, returning immediately when the optimum is reached. Preserve the
existing child `dfs` behavior and board-processing logic for cases where `ans`
is not yet zero.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3c918aa9-1cd4-4369-a766-037f7c8709c6

📥 Commits

Reviewing files that changed from the base of the PR and between b2f16a5 and 1b73166.

📒 Files selected for processing (3)
  • studies/week-02/clarityth/26070-보석수집로봇.md
  • studies/week-02/clarityth/5656-벽돌깨기.md
  • studies/week-02/clarityth/5658-보물상자비밀번호.md

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.

1 participant