Skip to content

solve: [W02] SWEA 26701 블록 제거 게임 - #6

Open
min9u wants to merge 1 commit into
mainfrom
week02/min9u
Open

solve: [W02] SWEA 26701 블록 제거 게임#6
min9u wants to merge 1 commit into
mainfrom
week02/min9u

Conversation

@min9u

@min9u min9u commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

📌 이번 PR 내용

  • 주차: W02
  • 작성자: @min9u

✅ 푼 문제 (SWEA)

번호 문제 링크
26701 블록제거게임

🧾 5요소 체크리스트

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

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

📋 규칙 체크

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

💬 리뷰어에게

🧠 이번 주 회고 (한 줄)

Summary by CodeRabbit

  • 문서
    • 블록 제거 게임의 구간 DP 풀이 방법과 점수 계산 전략을 정리했습니다.
    • 시간·공간 복잡도와 예외 처리 내용을 추가했습니다.
    • 하향식 메모이제이션 파이썬 코드 예시와 풀이 회고를 포함했습니다.

@github-actions
github-actions Bot requested a review from yeseoLee July 27, 2026 10:55
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

SWEA 1767 블록 제거 게임 문서에 문제 메타 정보, 구간 DP 풀이 설명, 메모이제이션 파이썬 코드, 초기 DFS 시도와 회고를 추가했다.

Changes

블록 제거 게임 풀이

Layer / File(s) Summary
문제 접근과 구간 DP 설계
studies/week-02/min9u/26071-블록 제거 게임.md
문제 정보와 완전탐색에서 구간 DP로 전환한 과정, 마지막으로 깨지는 블록을 기준으로 한 점화식, O(T × N³) 시간 및 O(N²) 공간 복잡도를 정리했다.
메모이제이션 DP 구현
studies/week-02/min9u/26071-블록 제거 게임.md
배열 양 끝에 1을 추가하고, cost(a,b) 재귀와 dp[a][b] != -1 검사를 사용해 구간 결과를 메모이제이션한다. 전체 구간과 원소 하나인 경우의 예외 처리 및 테스트케이스별 출력도 포함했다.
초기 시도와 풀이 회고
studies/week-02/min9u/26071-블록 제거 게임.md
초기 DFS 완전탐색 코드를 주석으로 남기고, DP 전환과 예외 처리에 대한 회고 내용을 추가했다.

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

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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.
Title check ✅ Passed 제목이 week 02의 SWEA 26701 블록 제거 게임 풀이 추가라는 핵심 변경을 정확히 가리킵니다.
✨ 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 week02/min9u

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

📥 Commits

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

📒 Files selected for processing (1)
  • studies/week-02/min9u/26071-블록 제거 게임.md

Comment on lines +1 to +7
# [SWEA 1767] 프로세서 연결하기

| 항목 | 내용 |
| :----------- | :--------------------------------------------------------------------------------------------- |
| 🔗 문제 | https://swexpertacademy.com/main/solvingProblem/solvingProblem.do |
| 📚 주제 | DP |
| 🎚️ 난이도 | D4 |

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

문제 식별자와 풀이 내용이 일치하지 않습니다.

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

Comment on lines +21 to +27
**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배 수준으로 극적으로 줄어든 셈입니다.)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚀 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

Comment on lines +23 to +25
리스트 앞뒤에 1을 붙여 n+2개 원소로 만든 뒤, dp[i][j] 형태의 구간을 정의합니다.
가능한 구간 (i, j)의 개수는 O(N²)개이고, 각 구간마다 "마지막으로 깨지는 블록 k"를 O(N)개 시도하며 값을 구합니다.
메모이제이션(dp[a][b] != -1 체크)으로 한 번 계산된 구간은 재계산하지 않으므로, 전체 계산량은 **구간 수(O(N²)) × 구간당 전이 비용(O(N)) = O(N³)**입니다.

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

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

Comment on lines +38 to +44
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] 것을 주의해야합니다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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

@min9u min9u changed the title solve: [W01] SWEA 26701 블록 제거 게임 solve: [W02] SWEA 26701 블록 제거 게임 Jul 27, 2026
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