solve: [W02] SWEA 5656, 5658, 26070, 26071 - #7
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughSWEA 26070, 26071, 5656, 5658의 풀이 문서와 Python 구현이 추가되었다. 각 문서에 문제별 알고리즘, 복잡도 분석, 코드, 회고가 포함되었다. Changes2주차 알고리즘 풀이
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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/Suyoung-Min/26070_보석수집로봇.md`:
- Line 13: In the Markdown document, add blank lines after each heading and
immediately before and after every fenced code block, including the sections
referenced by the repeated locations. Keep the existing python fence language
tags unchanged and preserve the code content.
- Around line 19-24: 다익스트라 상태 탐색에 `(y, x, 방향, turn_flag)`별 `visited` 또는 `dist`
완화 검사를 추가해 동일 상태의 더 큰 비용 경로가 힙에 중복 삽입되지 않도록 수정하세요. 각 상태를 처음 꺼낼 때만 확장하거나 더 짧은 거리일
때만 갱신하며, 가능하면 0/1 가중치 특성에 맞춰 `deque` 기반 0-1 BFS로 변경해 구간별 시간·공간 복잡도가 문서와 일치하도록
하세요.
In `@studies/week-02/Suyoung-Min/26071_블록제거게임.md`:
- Line 14: 백트래킹 시간 복잡도 설명을 O(N!)에서 O(N · N!)으로 수정하세요. 각 재귀 상태에서 좌·우 이웃을 최대
O(N)으로 탐색하고 메모이제이션 없이 N개 후보를 재귀 호출하는 실제 구현을 반영해 관련 설명과 적용 구간의 복잡도 표기를 일관되게
갱신하세요.
In `@studies/week-02/Suyoung-Min/5656_벽돌깨기.md`:
- Around line 33-34: copy.deepcopy를 제거하고, DFS 분기에서 grid를 복사하는 부분을 각 행의 얕은 복사로
변경하세요. 정수 원소만 포함된 list[list[int]] 구조의 동작은 유지하면서 모든 분기에서 발생하는 깊은 복사 비용을 줄여야 하며,
관련 복사 로직과 import copy를 함께 정리하세요.
In `@studies/week-02/Suyoung-Min/5658_보물상자비밀번호.md`:
- Line 13: Markdown의 ## 1. 접근 방법 제목 뒤와 모든 fenced code block 앞뒤에 빈 줄을 추가해 MD022 및
MD031 경고를 해결하세요. 코드펜스의 python 언어 태그는 그대로 유지하고, 언급된 모든 위치에 동일하게 적용하세요.
- Around line 22-23: 수정된 보물상자 비밀번호 풀이의 공간 복잡도 설명을 O(n²)로 변경하고, hex_count가 최대
O(n)개의 길이 O(n) 문자열을 저장한다는 근거를 반영하세요. 후보를 저장하는 로직에서는 문자열을 즉시 16진수 정수로 변환해 중복 제거와
최종 변환을 통합하고, 관련 설명과 구현이 일치하도록 정리하세요.
- Around line 18-20: The complexity section should match the current deque
middle-indexing implementation: update time complexity to O(n³) and state
hex_count’s space complexity as O(n²). If changing the representation to a
string/list, update the implementation and complexity explanation consistently
to O(n² + C log C).
🪄 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: c7039de1-8dd7-4f13-b303-7c4f5d936203
📒 Files selected for processing (4)
studies/week-02/Suyoung-Min/26070_보석수집로봇.mdstudies/week-02/Suyoung-Min/26071_블록제거게임.mdstudies/week-02/Suyoung-Min/5656_벽돌깨기.mdstudies/week-02/Suyoung-Min/5658_보물상자비밀번호.md
|
|
||
| --- | ||
|
|
||
| ## 1. 접근 방법 |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Markdown 제목과 코드 펜스 뒤에 빈 줄을 추가하세요.
markdownlint의 MD022/MD031 경고대로 각 제목 다음과 코드 펜스 앞뒤에 빈 줄이 필요합니다. 코드 펜스의 python 언어 태그 자체는 올바릅니다.
Also applies to: 19-19, 23-23, 26-26, 33-34, 83-83
🧰 Tools
🪛 markdownlint-cli2 (0.23.1)
[warning] 13-13: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
🤖 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/Suyoung-Min/26070_보석수집로봇.md` at line 13, In the Markdown
document, add blank lines after each heading and immediately before and after
every fenced code block, including the sections referenced by the repeated
locations. Keep the existing python fence language tags unchanged and preserve
the code content.
Source: Linters/SAST tools
| ## 2. 시간 복잡도 | ||
| **O(J · n² log n)** — J = 보석 수(최대 ~n²), 구간마다 상태 `(y,x,방향,회전가능)` 다익스트라. | ||
| 전체적으로는 대략 `O(n⁴ log n)` 규모. | ||
|
|
||
| ## 3. 공간 복잡도 | ||
| **O(n²)** — 격자 저장 및 힙에 올라가는 상태 수(위치×방향×플래그 = n²×4×2). |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win
visited/dist 없이 다익스트라를 실행해 문서의 복잡도를 보장하지 못합니다.
현재는 같은 (y, x, 방향, turn_flag) 상태를 더 큰 비용의 경로로도 계속 힙에 넣습니다. 예를 들어 (0,1,오른쪽,True)에서 시계 방향으로 한 바퀴 돌면 같은 상태에 다시 도달할 수 있습니다. 따라서 힙 원소 수가 상태 수 O(n²)로 제한되지 않아, 문서의 O(J·n² log n) 시간 및 O(n²) 공간 복잡도가 실제 코드에 성립하지 않습니다. 최대 입력에서는 TLE 위험이 있습니다.
각 상태를 처음 꺼낼 때 방문 처리하거나 dist로 완화 여부를 확인하세요. 이 문제는 0/1 가중치이므로 deque를 이용한 0-1 BFS로 바꾸면 구간당 O(n²)까지 줄일 수 있습니다.
최소 수정 예시
q = []
+ visited = [[[[False] * 2 for _ in range(4)]
+ for _ in range(n)] for _ in range(n)]
heapq.heappush(q, (0, sy, sx, cur_d, not first_flag))
while q:
cost, y, x, direct, turn_flag = heapq.heappop(q)
+ if visited[y][x][direct][turn_flag]:
+ continue
+ visited[y][x][direct][turn_flag] = True경로 지침의 “시간 복잡도와 공간 복잡도가 실제 코드와 일치하는지 직접 계산” 및 “입력 최대치 기준 TLE 위험을 반드시 지적” 요구를 반영했습니다.
Also applies to: 55-76, 85-85
🧰 Tools
🪛 markdownlint-cli2 (0.23.1)
[warning] 19-19: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
[warning] 23-23: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
🤖 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/Suyoung-Min/26070_보석수집로봇.md` around lines 19 - 24, 다익스트라 상태
탐색에 `(y, x, 방향, turn_flag)`별 `visited` 또는 `dist` 완화 검사를 추가해 동일 상태의 더 큰 비용 경로가 힙에
중복 삽입되지 않도록 수정하세요. 각 상태를 처음 꺼낼 때만 확장하거나 더 짧은 거리일 때만 갱신하며, 가능하면 0/1 가중치 특성에 맞춰
`deque` 기반 0-1 BFS로 변경해 구간별 시간·공간 복잡도가 문서와 일치하도록 하세요.
Source: Path instructions
| --- | ||
|
|
||
| ## 1. 접근 방법 | ||
| "어떤 순서로 깰까"를 정방향으로 탐색하면 순열 `O(N!)`이라 TLE. |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win
백트래킹 복잡도를 O(N!)보다 정확히 설명해 주세요.
이 구현은 각 유효 상태마다 좌·우 이웃을 찾는 데 최대 O(N)이 걸리고, N개 후보를 모두 재귀 호출합니다. 메모이제이션도 없으므로 전체 최악 시간 복잡도는 O(N · N!)으로 보는 것이 정확합니다. 문서의 백트래킹 설명을 실제 코드 기준으로 수정해 주세요.
As per path instructions, 시간 복잡도는 실제 코드의 반복·탐색 비용까지 직접 계산해야 합니다.
Also applies to: 102-112, 127-130, 147-148
🤖 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/Suyoung-Min/26071_블록제거게임.md` at line 14, 백트래킹 시간 복잡도 설명을
O(N!)에서 O(N · N!)으로 수정하세요. 각 재귀 상태에서 좌·우 이웃을 최대 O(N)으로 탐색하고 메모이제이션 없이 N개 후보를 재귀
호출하는 실제 구현을 반영해 관련 설명과 적용 구간의 복잡도 표기를 일관되게 갱신하세요.
Source: Path instructions
| import copy | ||
| from collections import deque |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win
copy.deepcopy 대신 행 단위 복사를 사용하세요.
grid는 list[list[int]]이며 원소가 정수이므로 copy.deepcopy는 필요하지 않습니다. 모든 DFS 분기에서 반복되는 깊은 복사 비용이 최악 입력에서 TLE 여유를 줄일 수 있습니다. 아래처럼 복사하면 동일한 동작을 유지하면서 비용을 줄일 수 있습니다.
수정 예시
-import copy
from collections import deque
...
- ngrid = copy.deepcopy(grid)
+ ngrid = [row[:] for row in grid]문서의 전체 복잡도 표기 O(W^N · W·H)는 유지되지만, 실제 실행 시간의 상수 비용을 줄이는 개선입니다. 최대 입력으로 두 방식을 간단히 벤치마크해 확인해 주세요.
As per path instructions, SWEA 풀이에서는 최대 입력 기준 TLE 위험을 반드시 점검해야 합니다.
Also applies to: 96-97
🤖 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/Suyoung-Min/5656_벽돌깨기.md` around lines 33 - 34,
copy.deepcopy를 제거하고, DFS 분기에서 grid를 복사하는 부분을 각 행의 얕은 복사로 변경하세요. 정수 원소만 포함된
list[list[int]] 구조의 동작은 유지하면서 모든 분기에서 발생하는 깊은 복사 비용을 줄여야 하며, 관련 복사 로직과 import
copy를 함께 정리하세요.
Source: Path instructions
|
|
||
| --- | ||
|
|
||
| ## 1. 접근 방법 |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
Markdown lint 경고를 정리해 주세요.
제목 뒤에는 빈 줄을 추가하고, fenced code block 앞뒤에도 빈 줄을 추가해야 합니다(MD022, MD031). 코드펜스의 python 태그 자체는 올바릅니다.
Also applies to: 18-18, 22-22, 25-25, 32-33, 56-56
🧰 Tools
🪛 markdownlint-cli2 (0.23.1)
[warning] 13-13: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
🤖 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/Suyoung-Min/5658_보물상자비밀번호.md` at line 13, Markdown의 ## 1. 접근
방법 제목 뒤와 모든 fenced code block 앞뒤에 빈 줄을 추가해 MD022 및 MD031 경고를 해결하세요. 코드펜스의 python
언어 태그는 그대로 유지하고, 언급된 모든 위치에 동일하게 적용하세요.
Source: Linters/SAST tools
| ## 2. 시간 복잡도 | ||
| **O(n²/4)** — `n/4`번 회전 × 회전마다 4개 변(총 `n`자리) 읽기. 이후 정렬 O(C log C), C=후보 개수. | ||
| `n`이 작아(최대 ~28) 충분히 빠름. |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
python - <<'PY'
from collections import deque
import time
for n in (100, 200, 400):
side = n // 4
data = deque("0" * n)
start = time.perf_counter()
for _ in range(side):
for i in range(0, n, side):
for j in range(side):
data[i + j]
data.rotate(1)
print(n, time.perf_counter() - start)
PYRepository: DevJunz/coding-test-study-template
Length of output: 249
🏁 Script executed:
python3 - <<'PY'
from pathlib import Path
path = Path('studies/week-02/Suyoung-Min/5658_보물상자비밀번호.md')
print(path.exists())
print(path)
print(path.read_text(encoding='utf-8')[:4000])
PYRepository: DevJunz/coding-test-study-template
Length of output: 2107
🏁 Script executed:
python3 - <<'PY'
from pathlib import Path
path = Path('studies/week-02/Suyoung-Min/5658_보물상자비밀번호.md')
text = path.read_text(encoding='utf-8')
lines = text.splitlines()
for i, line in enumerate(lines, 1):
if 1 <= i <= 120:
print(f"{i:>4}: {line}")
PYRepository: DevJunz/coding-test-study-template
Length of output: 2416
🏁 Script executed:
python3 - <<'PY'
from pathlib import Path
path = Path('studies/week-02/Suyoung-Min/5658_보물상자비밀번호.md')
text = path.read_text(encoding='utf-8')
lines = text.splitlines()
for i, line in enumerate(lines, 1):
if 1 <= i <= 140:
print(f"{i:>4}: {line}")
PYRepository: DevJunz/coding-test-study-template
Length of output: 2416
🏁 Script executed:
python3 - <<'PY'
from pathlib import Path
path = Path('studies/week-02/Suyoung-Min/5658_보물상자비밀번호.md')
text = path.read_text(encoding='utf-8')
for i, line in enumerate(text.splitlines(), 1):
if 1 <= i <= 140:
print(f"{i:>4}: {line}")
PYRepository: DevJunz/coding-test-study-template
Length of output: 2416
시간·공간 복잡도 표기를 수정하세요.
treas[i + j]가 deque 중간 인덱싱이라 한 회전당O(n²), 이를n/4번 반복해 전체는O(n³)입니다. 지금의O(n²/4)는 실제 코드와 맞지 않습니다.hex_count도 길이n/4문자열을 최대n개 저장하므로 공간 복잡도는O(n²)로 보는 게 맞습니다.- 문자열/list로 바꾸면 구현과 복잡도 설명을
O(n² + C log C)수준으로 맞출 수 있습니다.
🧰 Tools
🪛 markdownlint-cli2 (0.23.1)
[warning] 18-18: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
🤖 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/Suyoung-Min/5658_보물상자비밀번호.md` around lines 18 - 20, The
complexity section should match the current deque middle-indexing
implementation: update time complexity to O(n³) and state hex_count’s space
complexity as O(n²). If changing the representation to a string/list, update the
implementation and complexity explanation consistently to O(n² + C log C).
Source: Path instructions
| ## 3. 공간 복잡도 | ||
| **O(n)** — 둘레 덱과 후보 집합. (자릿수·후보 수 모두 `n`에 비례) |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win
공간 복잡도는 O(n)이 아니라 O(n²)입니다.
hex_count가 최대 O(n)개의 길이 O(n) 문자열을 보관하므로 문자열 저장 공간이 O(n²)입니다. 후보를 삽입할 때 바로 16진수 정수로 변환하면 중복 제거와 최종 변환을 한 번에 처리할 수 있습니다.
개선 예시
- hex_count.add(num)
+ hex_count.add(int(num, 16))
- hex_list = sorted((int(x, 16) for x in hex_count), reverse=True)
+ hex_list = sorted(hex_count, reverse=True)Also applies to: 41-42, 47-50
🧰 Tools
🪛 markdownlint-cli2 (0.23.1)
[warning] 22-22: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
🤖 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/Suyoung-Min/5658_보물상자비밀번호.md` around lines 22 - 23, 수정된 보물상자
비밀번호 풀이의 공간 복잡도 설명을 O(n²)로 변경하고, hex_count가 최대 O(n)개의 길이 O(n) 문자열을 저장한다는 근거를
반영하세요. 후보를 저장하는 로직에서는 문자열을 즉시 16진수 정수로 변환해 중복 제거와 최종 변환을 통합하고, 관련 설명과 구현이 일치하도록
정리하세요.
Source: Path instructions
📌 이번 PR 내용
✅ 푼 문제 (SWEA)
🧾 5요소 체크리스트
각 풀이에 아래 5요소를 모두 작성했는지 확인합니다.
📋 규칙 체크
studies/week-XX/<깃허브ID>/<문제번호>-<문제이름>.md)💬 리뷰어에게
DP 연습 방식이나 좀 더 파이써닉하고 직관적인 코드 있다면 추천요망!
🧠 이번 주 회고 (한 줄)
DP 방식이 필요할 때, 떠올리기 너무 힘들다. DP 기초부터 다시 연습 시작해야겠다.
Summary by CodeRabbit