solve: [W02] SWEA 26701 블록 제거 게임 - #6
Conversation
📝 WalkthroughWalkthroughSWEA 1767 블록 제거 게임 문서에 문제 메타 정보, 구간 DP 풀이 설명, 메모이제이션 파이썬 코드, 초기 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: 4
🤖 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/min9u/26071-블록` 제거 게임.md:
- Around line 23-25: 수식 표현인 dp[i][j]와 dp[a][b]를 모두 인라인 코드 백틱으로 감싸고, `## 5. 실제
코드` 헤딩 바로 앞에 빈 줄을 추가해 Markdown lint 경고를 해결하세요.
- Around line 1-7: 문서 제목과 문제 링크가 실제 구현 대상인 블록 제거 게임과 일치하도록 수정하세요. 제목의 SWEA 문제
식별자를 블록 제거 게임의 식별자로 변경하고, 현재 일반 풀이 링크를 해당 문제의 직접 링크로 교체하세요.
- Around line 38-44: Update the DP explanation to distinguish the general
interval recurrence from the full-interval recurrence: use max(cost(a,k) +
cost(k,b) + li[a] * li[b]) for ordinary intervals, and max(cost(0,k) +
cost(k,n-1) + li[k]) for the whole interval. Replace incorrect arr[i][j] or
arr[k] notation with the actual li-based variable names consistently.
- Around line 21-27: 복잡도 설명에서 `50,000번 연산` 및 정확한 연산량·감소 배수 단정을 제거하세요. 경계값을 포함한
전이 후보 수와 재귀 호출·메모이제이션 조회까지 고려하면 해당 수치는 부정확하므로, `O(T × N³)` 복잡도와 주어진 제약에서 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: 74e907a2-ca6f-4a74-a9ba-1dcb6b744db2
📒 Files selected for processing (1)
studies/week-02/min9u/26071-블록 제거 게임.md
| # [SWEA 1767] 프로세서 연결하기 | ||
|
|
||
| | 항목 | 내용 | | ||
| | :----------- | :--------------------------------------------------------------------------------------------- | | ||
| | 🔗 문제 | https://swexpertacademy.com/main/solvingProblem/solvingProblem.do | | ||
| | 📚 주제 | DP | | ||
| | 🎚️ 난이도 | D4 | |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
문제 식별자와 풀이 내용이 일치하지 않습니다.
PR 목적과 구현은 블록 제거 게임인데 제목은 SWEA 1767 프로세서 연결하기로 되어 있습니다. 제목을 실제 문제 식별자로 수정하고, 문제 링크도 해당 문제의 직접 링크로 교체해주세요.
🤖 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/min9u/26071-블록` 제거 게임.md around lines 1 - 7, 문서 제목과 문제 링크가 실제
구현 대상인 블록 제거 게임과 일치하도록 수정하세요. 제목의 SWEA 문제 식별자를 블록 제거 게임의 식별자로 변경하고, 현재 일반 풀이 링크를
해당 문제의 직접 링크로 교체하세요.
Source: Path instructions
| **O(T × N³)** | ||
|
|
||
| 리스트 앞뒤에 1을 붙여 n+2개 원소로 만든 뒤, dp[i][j] 형태의 구간을 정의합니다. | ||
| 가능한 구간 (i, j)의 개수는 O(N²)개이고, 각 구간마다 "마지막으로 깨지는 블록 k"를 O(N)개 시도하며 값을 구합니다. | ||
| 메모이제이션(dp[a][b] != -1 체크)으로 한 번 계산된 구간은 재계산하지 않으므로, 전체 계산량은 **구간 수(O(N²)) × 구간당 전이 비용(O(N)) = O(N³)**입니다. | ||
| 테스트케이스가 T개이므로 총 시간복잡도는 **O(T × N³)**이며, N≤10, T≤50 제약에서는 최대 약 50 × 10³ = 50,000번 연산 수준이라 충분히 빠릅니다. | ||
| (참고: 완전탐색은 O(N!)이었던 것과 비교하면, N=10 기준 3,628,800배 → 1,000배 수준으로 극적으로 줄어든 셈입니다.) |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win
복잡도는 맞지만 50,000번 연산 계산은 부정확합니다.
경계값을 추가한 크기는 M = N + 2이고, 실제 전이 후보 수는
Σ(M-L)(L-1) (L=3..M-1)로, N=10일 때 테스트케이스당 210회입니다. 재귀 호출과 메모이제이션 조회까지 포함한 전체 연산 수를 50 × 10³으로 단정하지 말고, O(T×N³) 및 TLE 위험이 낮다는 정도로 서술하는 편이 정확합니다.
🧰 Tools
🪛 markdownlint-cli2 (0.23.0)
[warning] 23-23: Reference links and images should use a label that is defined
Missing link or image reference definition: "j"
(MD052, reference-links-images)
[warning] 25-25: Reference links and images should use a label that is defined
Missing link or image reference definition: "b"
(MD052, reference-links-images)
🤖 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/min9u/26071-블록` 제거 게임.md around lines 21 - 27, 복잡도 설명에서
`50,000번 연산` 및 정확한 연산량·감소 배수 단정을 제거하세요. 경계값을 포함한 전이 후보 수와 재귀 호출·메모이제이션 조회까지 고려하면
해당 수치는 부정확하므로, `O(T × N³)` 복잡도와 주어진 제약에서 TLE 위험이 낮다는 내용만 유지해 서술을 수정하세요.
Source: Path instructions
| 리스트 앞뒤에 1을 붙여 n+2개 원소로 만든 뒤, dp[i][j] 형태의 구간을 정의합니다. | ||
| 가능한 구간 (i, j)의 개수는 O(N²)개이고, 각 구간마다 "마지막으로 깨지는 블록 k"를 O(N)개 시도하며 값을 구합니다. | ||
| 메모이제이션(dp[a][b] != -1 체크)으로 한 번 계산된 구간은 재계산하지 않으므로, 전체 계산량은 **구간 수(O(N²)) × 구간당 전이 비용(O(N)) = O(N³)**입니다. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Markdown lint 경고를 수정해주세요.
dp[i][j], dp[a][b]는 백틱으로 감싸고, ## 5. 실제 코드 앞에는 빈 줄을 추가해야 합니다.
Also applies to: 45-45
🧰 Tools
🪛 markdownlint-cli2 (0.23.0)
[warning] 23-23: Reference links and images should use a label that is defined
Missing link or image reference definition: "j"
(MD052, reference-links-images)
[warning] 25-25: Reference links and images should use a label that is defined
Missing link or image reference definition: "b"
(MD052, reference-links-images)
🤖 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/min9u/26071-블록` 제거 게임.md around lines 23 - 25, 수식 표현인
dp[i][j]와 dp[a][b]를 모두 인라인 코드 백틱으로 감싸고, `## 5. 실제 코드` 헤딩 바로 앞에 빈 줄을 추가해 Markdown
lint 경고를 해결하세요.
Sources: Path instructions, Linters/SAST tools
| 1. 핵심 아이디어는 **마지막으로 깨지는 블록** 만 고려하면 간단한 DP 문제가 된다는 것입니다. 처음 문제를 직관적으로 보았을 때에는 블록들이 깨지는 순서를 모두 고려해야 할 것 같지만 그렇지 않습니다. | ||
| **특정 구간 내**(i,j)에서의 최대 점수를 DP(i,j)라고 정의하고, **마지막으로 깨지는 블록**을 k라고 정의하면 다음과 같이 부분식을 만들 수 있습니다. | ||
| DP(i,j) = DP(i,k) + DP(k,j) + arr[i]*arr[j] | ||
| 마지막에 깨지는 블록이 무엇이 되든 마지막 점수는 arr[i]*arr[j]가 됩니다. | ||
|
|
||
| 2. 입력된 array 처음과 끝에 원소 1을 추가해 문제를 더 단순히 만들었습니다. 좋은 아이디어라 다른 문제에서도 응용될 것 같습니다 | ||
| 3. 마지막으로 깨지는 블록은 cost가 arr[i]*arr[j]가 아니라 arr[k] 것을 주의해야합니다. |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
점화식 설명을 실제 코드의 두 경우로 분리해주세요.
현재 설명은 arr[i]*arr[j]와 arr[k]를 혼용해 모순됩니다. 정확한 설명은 다음과 같아야 합니다.
- 일반 구간:
max(cost(a,k) + cost(k,b) + li[a] * li[b]) - 전체 구간: 마지막에 남는 블록
k의 점수li[k]를 더해max(cost(0,k) + cost(k,n-1) + li[k]) arr[i][j]는 잘못된 표기이므로li[a] * li[b]등 실제 변수명으로 수정
이 부분은 독자가 설명만 보고 구현할 때 오답을 만들 수 있습니다.
수정 예시
- dp[i][j] = max(dp[i][k] + dp[k][j] + arr[i][j])
+ cost(a, b) = max(cost(a, k) + cost(k, b) + li[a] * li[b])
+ answer = max(cost(0, k) + cost(k, n - 1) + li[k])Also applies to: 48-57
🤖 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/min9u/26071-블록` 제거 게임.md around lines 38 - 44, Update the DP
explanation to distinguish the general interval recurrence from the
full-interval recurrence: use max(cost(a,k) + cost(k,b) + li[a] * li[b]) for
ordinary intervals, and max(cost(0,k) + cost(k,n-1) + li[k]) for the whole
interval. Replace incorrect arr[i][j] or arr[k] notation with the actual
li-based variable names consistently.
Source: Path instructions
📌 이번 PR 내용
✅ 푼 문제 (SWEA)
🧾 5요소 체크리스트
각 풀이에 아래 5요소를 모두 작성했는지 확인합니다.
📋 규칙 체크
studies/week-XX/<깃허브ID>/<문제번호>-<문제이름>.md)💬 리뷰어에게
🧠 이번 주 회고 (한 줄)
Summary by CodeRabbit