Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# [SWEA 26070] ๋ณด์„ ์ˆ˜์ง‘ ๋กœ๋ด‡

| ํ•ญ๋ชฉ | ๋‚ด์šฉ |
|:---|:---|
| ๐Ÿ”— ๋ฌธ์ œ | https://swexpertacademy.com/main/code/userProblem/userProblemDetail.do?contestProbId=AZwmBfua3q3HBIT3 |
| ๐Ÿ“š ์ฃผ์ œ | 0-1 BFS |
| ๐ŸŽš๏ธ ๋‚œ์ด๋„ | D4 |
| โฑ๏ธ ์†Œ์š” ์‹œ๊ฐ„ | 1H (์‹คํŒจ) |
| ๐Ÿ” ๋‹ค์‹œ ํ’€๊ธฐ | ์˜ˆ |

---

## 1. ์ ‘๊ทผ ๋ฐฉ๋ฒ•

* ์ตœ๋‹จ ๊ฑฐ๋ฆฌ๊ฐ€ ์•„๋‹Œ ์ตœ์†Œ ํšŒ์ „ ํšŸ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ
* ์ด๋™์— ๋”ฐ๋ฅธ ๋น„์šฉ์ด ๋‹ค๋ฆ„ -> ๋‹ค์ต์ŠคํŠธ๋ผ
* ๊ฐ€์ค‘์น˜๊ฐ€ ์˜ค์ง 0๊ณผ 1 -> ๋‹ค์ต์ŠคํŠธ๋ผ ๋Œ€์‹  0-1 BFS

## 2. ์‹œ๊ฐ„ ๋ณต์žก๋„

**O(N^2 * M)** โ€”

* (N * N ์ขŒํ‘œ) * (4 ๋ฐฉํ–ฅ) * (M ๋ชฉํ‘œ๋ฌผ ๊ฐœ์ˆ˜) * (2 ํšŒ์ „ ์—ฌ๋ถ€ ์ƒํƒœ)

## 3. ๊ณต๊ฐ„ ๋ณต์žก๋„

**O(N^2 * M)** โ€”

* ๋ฐฉ๋ฌธ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ `visited` Set๊ณผ ํƒ์ƒ‰์„ ์œ„ํ•œ `deque`์— ์ตœ๋Œ€ ์ƒํƒœ ๊ณต๊ฐ„์˜ ํฌ๊ธฐ๋งŒํผ ๋ฐ์ดํ„ฐ๊ฐ€ ์ ์žฌ

## 4. ํ•ต์‹ฌ ํ’€์ด ๋ฐฉ๋ฒ•

* **0-1 BFS:** `que.appendleft()`๋ฅผ ์‚ฌ์šฉํ•ด ๋น„์šฉ์ด 0์ธ ์ง์ง„์„ ๋ฑ์˜ ์ตœ์ƒ๋‹จ์— ๋ฐฐ์น˜ํ•˜๊ณ , `que.append()`๋ฅผ ์‚ฌ์šฉํ•ด ๋น„์šฉ์ด 1์ธ ์šฐํšŒ์ „์„ ๋’ค์— ๋ฐฐ์น˜ํ•˜์—ฌ ํƒ์ƒ‰ ์šฐ์„ ์ˆœ์œ„๋ฅผ ๋ณด์žฅ
* **์ƒํƒœ ๊ด€๋ฆฌ:** `(x, y, d, jewel, flag)`๋ฅผ ํŠœํ”Œ๋กœ ๋ฌถ์–ด ๋ฐฉ๋ฌธ ์ฒ˜๋ฆฌ(`visited`)์˜ ํ‚ค๋กœ ์‚ฌ์šฉ

## 5. ์‹ค์ œ ์ฝ”๋“œ

```python
from collections import deque


def solution(n, m, board):
dx, dy = [0, 1, 0, -1], [1, 0, -1, 0]
visited = set()
que = deque([(0, 0, 0, 0, 1, False)])

while que:
x, y, d, rotate, jewel, flag = que.popleft()

if board[x][y] == jewel:
jewel += 1
flag = False
if jewel == m + 1:
return rotate

state = (x, y, d, jewel, flag)
if state in visited:
continue
visited.add(state)

# ์ง์ง„
nx, ny = x + dx[d], y + dy[d]
if 0 <= nx < n and 0 <= ny < n:
que.appendleft((nx, ny, d, rotate, jewel, False))

# ํšŒ์ „
if not flag:
que.append((x, y, (d + 1) % 4, rotate + 1, jewel, True))

return -1


T = int(input())
for test_case in range(1, T + 1):
N = int(input())
BOARD = [list(map(int, input().split())) for _ in range(N)]
M = max([max(row) for row in BOARD])
answer = solution(N, M, BOARD)
print(f"#{test_case} {answer}")

```

---

### ํšŒ๊ณ  (์„ ํƒ)
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# [SWEA 26071] ๋ธ”๋ก ์ œ๊ฑฐ ๊ฒŒ์ž„

| ํ•ญ๋ชฉ | ๋‚ด์šฉ |
|:---|:---|
| ๐Ÿ”— ๋ฌธ์ œ | https://swexpertacademy.com/main/code/userProblem/userProblemDetail.do?contestProbId=AZwmCVWq3uLHBIT3& |
| ๐Ÿ“š ์ฃผ์ œ | ๋ฉ”๋ชจ์ด์ œ์ด์…˜ + ๋ถ„ํ•  ์ •๋ณต (DP) |
| ๐ŸŽš๏ธ ๋‚œ์ด๋„ | D4 |
| โฑ๏ธ ์†Œ์š” ์‹œ๊ฐ„ | 1h 30m (์‹คํŒจ) |
| ๐Ÿ” ๋‹ค์‹œ ํ’€๊ธฐ | ์˜ˆ |

---

## 1. ์ ‘๊ทผ ๋ฐฉ๋ฒ•

* ์ฒ˜์Œ ์ฝ”๋“œ๋Š” `permutations`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ธ”๋ก์„ ๊นจ๋Š” ๋ชจ๋“  ์ˆœ์„œ๋ฅผ ํƒ์ƒ‰ํ•˜๋Š” ์™„์ „ ํƒ์ƒ‰ ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผ
* ์ˆœ์—ด์„ ์ด์šฉํ•œ ๋ฐฉ์‹์€ N์ด ์ปค์งˆ ๊ฒฝ์šฐ ํƒ์ƒ‰ ๋ฒ”์œ„๊ฐ€ ๊ธฐํ•˜๊ธ‰์ˆ˜์ ์œผ๋กœ ๋Š˜์–ด๋‚˜ ์‹œ๊ฐ„ ์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒ
* ์ตœ์ ํ™”๋ฅผ ์œ„ํ•ด ๋ฉ”๋ชจ์ด์ œ์ด์…˜ ๋„์ž… -> ํŠน์ • ๊ตฌ๊ฐ„ `[i, j]`์—์„œ ์ฒ˜์Œ ๊นฐ ๋ธ”๋ก์ด ์•„๋‹Œ, **๊ฐ€์žฅ ๋งˆ์ง€๋ง‰์— ๊นฐ ๋ธ”๋ก**์„ `mid`๋กœ ์„ค์ •
* ์ด๋ฅผ ํ†ตํ•ด ๋‚จ์€ ๋ธ”๋ก๋“ค์ด ์„œ๋กœ ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๋Š” ๋‘ ๊ฐœ์˜ ๋…๋ฆฝ์ ์ธ ๋ถ€๋ถ„ ๋ฌธ์ œ(`[i, mid - 1]`์™€ `[mid + 1, j]`)๋กœ ๋‚˜๋ˆ„๋Š” ๋ถ„ํ•  ์ •๋ณต ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผ

## 2. ์‹œ๊ฐ„ ๋ณต์žก๋„

**O(Nยณ)** โ€”

* DP ํ…Œ์ด๋ธ”์˜ ์ƒํƒœ(State) ๊ฐœ์ˆ˜๋Š” `i`๋ถ€ํ„ฐ `j`๊นŒ์ง€์˜ ์กฐํ•ฉ์ด๋ฏ€๋กœ O(Nยฒ)
* ๊ฐ ์ƒํƒœ `dp[i][j]`๋ฅผ ๊ณ„์‚ฐํ•  ๋•Œ, ๋ถ„ํ• ์  `mid`๋ฅผ `i`๋ถ€ํ„ฐ `j`๊นŒ์ง€ ์ˆœํšŒํ•˜๋ฉฐ ์ตœ๋Œ“๊ฐ’์„ ์ฐพ์œผ๋ฏ€๋กœ O(N)์˜ ์‹œ๊ฐ„์ด ์ถ”๊ฐ€๋กœ ์†Œ์š”
* ๋”ฐ๋ผ์„œ ์ด O(Nยฒ) * O(N) = O(Nยณ)
Comment on lines +20 to +26

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

์ „์ฒด ์ž…๋ ฅ ๊ธฐ์ค€ ๋ณต์žก๋„๋„ ๋ช…์‹œํ•ด ์ฃผ์„ธ์š”.

ํ˜„์žฌ O(Nยณ) ๊ณ„์‚ฐ์€ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค 1๊ฐœ ๊ธฐ์ค€์œผ๋กœ๋Š” ๋งž์Šต๋‹ˆ๋‹ค. ๋‹ค๋งŒ ์‹ค์ œ ์ฝ”๋“œ๋Š” T๊ฐœ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋ฅผ ์ˆœํšŒํ•˜๋ฏ€๋กœ ์ „์ฒด ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š” O(TยทNยณ)(๋˜๋Š” O(ฮฃN_tยณ))์ž…๋‹ˆ๋‹ค. ๋ฌธ์„œ์— โ€œํ…Œ์ŠคํŠธ ์ผ€์ด์Šค 1๊ฐœ ๊ธฐ์ค€โ€์ด๋ผ๊ณ  ๋ช…์‹œํ•ด ์ฃผ์„ธ์š”.

์ˆ˜์ • ์˜ˆ์‹œ
-**O(Nยณ)** โ€”
+**ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค 1๊ฐœ ๊ธฐ์ค€ O(Nยณ), ์ „์ฒด ์ž…๋ ฅ ๊ธฐ์ค€ O(TยทNยณ)** โ€”
๐Ÿ“ 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
## 2. ์‹œ๊ฐ„ ๋ณต์žก๋„
**O(Nยณ)** โ€”
* DP ํ…Œ์ด๋ธ”์˜ ์ƒํƒœ(State) ๊ฐœ์ˆ˜๋Š” `i`๋ถ€ํ„ฐ `j`๊นŒ์ง€์˜ ์กฐํ•ฉ์ด๋ฏ€๋กœ O(Nยฒ)
* ๊ฐ ์ƒํƒœ `dp[i][j]`๋ฅผ ๊ณ„์‚ฐํ•  ๋•Œ, ๋ถ„ํ• ์  `mid`๋ฅผ `i`๋ถ€ํ„ฐ `j`๊นŒ์ง€ ์ˆœํšŒํ•˜๋ฉฐ ์ตœ๋Œ“๊ฐ’์„ ์ฐพ์œผ๋ฏ€๋กœ O(N)์˜ ์‹œ๊ฐ„์ด ์ถ”๊ฐ€๋กœ ์†Œ์š”
* ๋”ฐ๋ผ์„œ ์ด O(Nยฒ) * O(N) = O(Nยณ)
## 2. ์‹œ๊ฐ„ ๋ณต์žก๋„
**ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค 1๊ฐœ ๊ธฐ์ค€ O(Nยณ), ์ „์ฒด ์ž…๋ ฅ ๊ธฐ์ค€ O(TยทNยณ)** โ€”
* DP ํ…Œ์ด๋ธ”์˜ ์ƒํƒœ(State) ๊ฐœ์ˆ˜๋Š” `i`๋ถ€ํ„ฐ `j`๊นŒ์ง€์˜ ์กฐํ•ฉ์ด๋ฏ€๋กœ O(Nยฒ)
* ๊ฐ ์ƒํƒœ `dp[i][j]`๋ฅผ ๊ณ„์‚ฐํ•  ๋•Œ, ๋ถ„ํ• ์  `mid`๋ฅผ `i`๋ถ€ํ„ฐ `j`๊นŒ์ง€ ์ˆœํšŒํ•˜๋ฉฐ ์ตœ๋Œ“๊ฐ’์„ ์ฐพ์œผ๋ฏ€๋กœ O(N)์˜ ์‹œ๊ฐ„์ด ์ถ”๊ฐ€๋กœ ์†Œ์š”
* ๋”ฐ๋ผ์„œ ์ด O(Nยฒ) * O(N) = O(Nยณ)
๐Ÿค– 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/yeseolee/26071-๋ธ”๋ก` ์ œ๊ฑฐ ๊ฒŒ์ž„.md around lines 20 - 26, ์‹œ๊ฐ„ ๋ณต์žก๋„ ์„ค๋ช…์—
ํ˜„์žฌ O(Nยณ) ๋ถ„์„์ด ๋‹จ์ผ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ๊ธฐ์ค€์ž„์„ ๋ช…์‹œํ•˜๊ณ , T๊ฐœ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋ฅผ ๋ชจ๋‘ ์ฒ˜๋ฆฌํ•˜๋Š” ์ „์ฒด ๋ณต์žก๋„๋ฅผ O(TยทNยณ) ๋˜๋Š”
O(ฮฃN_tยณ)๋กœ ์ถ”๊ฐ€ํ•ด ์ฃผ์„ธ์š”.

Source: Path instructions


## 3. ๊ณต๊ฐ„ ๋ณต์žก๋„

**O(Nยฒ)** โ€”

* ๊ณ„์‚ฐ๋œ ๊ตฌ๊ฐ„ ์ ์ˆ˜์˜ ์ตœ๋Œ“๊ฐ’์„ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•œ 2์ฐจ์› `dp` ๋ฐฐ์—ด์˜ ํฌ๊ธฐ๊ฐ€ N x N์ด๋ฏ€๋กœ O(Nยฒ)์˜ ๊ณต๊ฐ„์ด ํ•„์š”

## 4. ํ•ต์‹ฌ ํ’€์ด ๋ฐฉ๋ฒ•

* **๋งˆ์ง€๋ง‰์— ํ„ฐ์งˆ ๋ธ”๋ก ๊ธฐ์ค€:** ์ฒ˜์Œ๋ถ€ํ„ฐ ์–ด๋–ค ๋ธ”๋ก์„ ํ„ฐ๋œจ๋ฆด์ง€ ๊ณ ๋ฅด๋ฉด, ํ„ฐ์ง„ ๋ธ”๋ก์œผ๋กœ ์ธํ•ด ์ธ์ ‘ ๋ธ”๋ก์ด ๊ณ„์† ๋ณ€ํ•˜์—ฌ ๋ถ€๋ถ„ ๋ฌธ์ œ๋ฅผ ๋…๋ฆฝ์ ์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์—†์Œ
* **๋ฉ”๋ชจ์ด์ œ์ด์…˜:** `dp[i][j]`๋ฅผ `i`๋ฒˆ์งธ๋ถ€ํ„ฐ `j`๋ฒˆ์งธ ๋ธ”๋ก๊นŒ์ง€ ํ„ฐ๋œจ๋ ธ์„ ๋•Œ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€ ์ ์ˆ˜๋กœ ์ •์˜

## 5-1. ์‹ค์ œ ์ฝ”๋“œ

```python
def solution(n, arr):
dp = [[-1] * (n) for _ in range(n)]

# ๋‹จ์ผ ๋ธ”๋ก ๋ถ€์ˆ˜๊ณ  ์ ์ˆ˜ ํš๋“
def get_boundary_score(i, j, mid):
left, right = i - 1, j + 1
if left >= 0 and right < n:
return arr[left] * arr[right]
elif left >= 0:
return arr[left]
elif right < n:
return arr[right]
else:
return arr[mid]

# ๊ตฌ๊ฐ„ ์ ์ˆ˜ ์ตœ๋Œ€๊ฐ’ (๋ถ„ํ•  ์ •๋ณต)
def get_max_score(i, j):
if i > j:
return 0

if dp[i][j] != -1:
return dp[i][j]

max_score = 0
for mid in range(i, j + 1):
cur_score = (
get_max_score(i, mid - 1)
+ get_boundary_score(i, j, mid)
+ get_max_score(mid + 1, j)
)
max_score = max(max_score, cur_score)

dp[i][j] = max_score
return max_score

return get_max_score(0, n - 1)

T = int(input())
for test_case in range(1, T + 1):
N = int(input())
K = list(map(int, input().split()))
answer = solution(N, K)
print(f"#{test_case} {answer}")

```

## 5-2. ์ž˜๋ชป๋œ ์ฝ”๋“œ (ํ…Œ์ผ€๋งŒ ๊ฒฝ์šฐ ํ†ต๊ณผ)
```python
def get_score(n,arr,order):
score = 0

for idx,mid in enumerate(order):
left,right = mid-1, mid+1
while True:
if arr[left] == 0:
left -= 1
continue
if arr[right] == 0:
right += 1
continue
break

if idx != len(order)-1:
score += arr[left] * arr[right]
arr[mid] = 0
else:
case_1 = arr[left] * arr[right] + max(arr[left],arr[right]) *2
case_2 = arr[mid] * 3
score += max(case_1,case_2)

return score


def solution(n, arr):
if n == 1:
return arr[0]
if n == 2:
return max(arr) * 2

max_score = 0
ps = permutations(range(1,n-1), n-2)

for p in ps:
score = get_score(n,arr[::],p)
Comment on lines +115 to +125

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

๋น„๊ต์šฉ ์ฝ”๋“œ์— permutations import๋ฅผ ์ถ”๊ฐ€ํ•ด ์ฃผ์„ธ์š”.

ํ˜„์žฌ ์ฝ”๋“œ ๋ธ”๋ก์—๋Š” from itertools import permutations๊ฐ€ ์—†์–ด ๊ทธ๋Œ€๋กœ ์‹คํ–‰ํ•˜๋ฉด NameError๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

์ˆ˜์ • ์˜ˆ์‹œ
+from itertools import permutations
+
 def solution(n, arr):
๐Ÿ“ 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
def solution(n, arr):
if n == 1:
return arr[0]
if n == 2:
return max(arr) * 2
max_score = 0
ps = permutations(range(1,n-1), n-2)
for p in ps:
score = get_score(n,arr[::],p)
from itertools import permutations
def solution(n, arr):
if n == 1:
return arr[0]
if n == 2:
return max(arr) * 2
max_score = 0
ps = permutations(range(1,n-1), n-2)
for p in ps:
score = get_score(n,arr[::],p)
๐Ÿค– 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/yeseolee/26071-๋ธ”๋ก` ์ œ๊ฑฐ ๊ฒŒ์ž„.md around lines 115 - 125, ๋น„๊ต์šฉ ์ฝ”๋“œ์—์„œ
solution์ด ์‚ฌ์šฉํ•˜๋Š” permutations๋ฅผ ์ •์˜๋œ ์ด๋ฆ„์œผ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋„๋ก itertools์˜ permutations๋ฅผ
importํ•˜์„ธ์š”. solution๊ณผ get_score์˜ ๊ธฐ์กด ๋กœ์ง์€ ๋ณ€๊ฒฝํ•˜์ง€ ๋ง๊ณ , ํ•ด๋‹น ์ฝ”๋“œ ๋ธ”๋ก์˜ import ์˜์—ญ์— ์ถ”๊ฐ€ํ•˜์„ธ์š”.

max_score = max(max_score,score)

return max_score
Comment on lines +115 to +128

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

์ˆœ์—ด ๊ตฌํ˜„์˜ ์‹ค์ œ ๋ณต์žก๋„์™€ TLE ์œ„ํ—˜์„ ๊ตฌ์ฒด์ ์œผ๋กœ ๊ธฐ๋กํ•ด ์ฃผ์„ธ์š”.

permutations(range(1, n - 1), n - 2)๋Š” (N-2)!๊ฐœ์˜ ์ˆœ์„œ๋ฅผ ํƒ์ƒ‰ํ•˜๊ณ , ๊ฐ ์ˆœ์„œ์˜ get_score๋„ ์ตœ์•… O(Nยฒ)๊นŒ์ง€ ๊ฑธ๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋‹น ์ตœ์•… ๋ณต์žก๋„๋Š” O((N-2)!ยทNยฒ) ์ˆ˜์ค€์ด๋ฉฐ, ์ž…๋ ฅ์ด ์กฐ๊ธˆ๋งŒ ์ปค์ ธ๋„ ์‹œ๊ฐ„ ์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ํ˜„์žฌ์˜ โ€œ๊ธฐํ•˜๊ธ‰์ˆ˜์ ์œผ๋กœ ์ฆ๊ฐ€โ€๋ผ๋Š” ์„ค๋ช…์„ ์ด ๊ทผ๊ฑฐ๋กœ ๋ณด์™„ํ•ด ์ฃผ์„ธ์š”.

๐Ÿค– 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/yeseolee/26071-๋ธ”๋ก` ์ œ๊ฑฐ ๊ฒŒ์ž„.md around lines 115 - 128, Update
the explanation for solution to explicitly state that permutations(range(1, n -
1), n - 2) explores (N-2)! orders and get_score can take O(Nยฒ) per order,
yielding worst-case O((N-2)!ยทNยฒ) per test case and causing TLE as input size
grows. Replace the vague โ€œexponential growthโ€ description with this concrete
complexity analysis.

Source: Path instructions




T = int(input())
for test_case in range(1, T + 1):
N = int(input())
K = list(map(int,input().split()))
answer = solution(N,K)
print(f"#{test_case} {answer}")
```

---

### ํšŒ๊ณ  (์„ ํƒ)

* "๋งˆ์ง€๋ง‰์— ์ˆ˜ํ–‰ํ•  ์ž‘์—…"์„ ๊ธฐ์ค€์œผ๋กœ ๋‚˜๋ˆ„๋Š” ๊ตฌ๊ฐ„ DP์˜ ์ „ํ˜•์ ์ธ ํ…Œํฌ๋‹‰(๋ฆฌํŠธ์ฝ”๋“œ 'Burst Balloons' ์œ ํ˜•)์„ ์ˆ™์ง€ํ•ด ๋‘๋ฉด ์œ ์‚ฌํ•œ ๋ฌธ์ œ์— ๋ฐ”๋กœ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. MM ๋ฏผ๊ตฌ๋‹˜์ด ๊ณต์œ ํ•˜์‹  ๋งํฌ ํ’€์–ด๋ณด์‹œ๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค.
125 changes: 125 additions & 0 deletions studies/week-02/yeseolee/5566-๋ฒฝ๋Œ ๊นจ๊ธฐ.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# [SWEA 5566] ๋ฒฝ๋Œ ๊นจ๊ธฐ

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

๐Ÿ—„๏ธ Data Integrity & Integration | ๐ŸŸก Minor | โšก Quick win

๋ฌธ์ œ ๋ฒˆํ˜ธ๋ฅผ 5656์œผ๋กœ ํ†ต์ผํ•ด ์ฃผ์„ธ์š”.

PR ๋ชฉํ‘œ์™€ ํŒŒ์ผ ๊ฒฝ๋กœ๋Š” SWEA 5656์ธ๋ฐ ์ œ๋ชฉ๊ณผ ํŒŒ์ผ๋ช…์€ 5566์œผ๋กœ ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ํŒŒ์ผ์„ studies/week-02/yeseolee/5656-๋ฒฝ๋Œ ๊นจ๊ธฐ.md๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ์ œ๋ชฉยท๋งํฌ๋„ ํ•จ๊ป˜ ํ™•์ธํ•ด ์ฃผ์„ธ์š”. SWEA ์ž๋ฃŒ์—์„œ๋„ 5656์€ ๋ฒฝ๋Œ ๊นจ๊ธฐ ๋ฌธ์ œ๋กœ ์‹๋ณ„๋ฉ๋‹ˆ๋‹ค. (swexpertacademy.com)

๐Ÿค– 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/yeseolee/5566-๋ฒฝ๋Œ` ๊นจ๊ธฐ.md at line 1, ๋ฌธ์„œ์˜ ๋ฌธ์ œ ๋ฒˆํ˜ธ๋ฅผ 5566์—์„œ 5656์œผ๋กœ
ํ†ต์ผํ•˜์„ธ์š”. ํŒŒ์ผ๋ช…์„ 5656-๋ฒฝ๋Œ ๊นจ๊ธฐ.md๋กœ ๋ณ€๊ฒฝํ•˜๊ณ , ๋ฌธ์„œ ์ œ๋ชฉ๊ณผ ๋‚ด๋ถ€ ๋งํฌ์— ๋‚จ์•„ ์žˆ๋Š” 5566 ํ‘œ๊ธฐ๋„ 5656์œผ๋กœ ์ˆ˜์ •ํ•˜์„ธ์š”.


| ํ•ญ๋ชฉ | ๋‚ด์šฉ |
|:---|:---|
| ๐Ÿ”— ๋ฌธ์ œ | https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRQm6qfL0DFAUo |
| ๐Ÿ“š ์ฃผ์ œ | BFS + ๋ฐฑํŠธ๋ž˜ํ‚น |
| ๐ŸŽš๏ธ ๋‚œ์ด๋„ | ์ƒ |
| โฑ๏ธ ์†Œ์š” ์‹œ๊ฐ„ | 1h 30m |
| ๐Ÿ” ๋‹ค์‹œ ํ’€๊ธฐ | ์˜ˆ |

---

## 1. ์ ‘๊ทผ ๋ฐฉ๋ฒ•

* **๋ฐฐ์—ด ํšŒ์ „:** 2์ฐจ์› ๋ฐฐ์—ด์˜ ์ค‘๋ ฅ ์ž‘์šฉ(๋นˆ ๊ณต๊ฐ„์„ ์ฑ„์šฐ๋ฉฐ ์•„๋ž˜๋กœ ๋–จ์–ด์ง€๋Š” ๊ฒƒ)์„ ์‰ฝ๊ฒŒ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ๋ณด๋“œ๋ฅผ ์‹œ๊ณ„ ๋ฐฉํ–ฅ์œผ๋กœ 90๋„ ํšŒ์ „. ์—ด์ด ํ–‰์œผ๋กœ ๋ณ€ํ™˜๋˜๋ฉฐ, ๋‹จ์ˆœํžˆ 0์„ ์ œ์™ธํ•œ ๋ฐฐ์—ด์„ ๋ฌถ๊ณ  ๋’ค์— 0์„ ์ฑ„์šฐ๋Š” ๋ฐฉ์‹์œผ๋กœ ์ค‘๋ ฅ์„ ๊ตฌํ˜„
* **์—ฐ์‡„ ํญ๋ฐœ (BFS):** ๋ฒฝ๋Œ์ด ๊นจ์งˆ ๋•Œ ์ฃผ๋ณ€ ๋ฒฝ๋Œ๋„ ์—ฐ์‡„์ ์œผ๋กœ ๊นจ์ง€๋ฏ€๋กœ, ์ด๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด BFS ์‚ฌ์šฉ
* **๋ฐฑํŠธ๋ž˜ํ‚น:** ๋ณด๋“œ์˜ ์ƒํƒœ๋ฅผ ๋ฐฑ์—…(`prev_board`)ํ•˜๊ณ , ํŠน์ • ์—ด์— ๊ตฌ์Šฌ์„ ๋–จ์–ด๋œจ๋ฆฐ ๋’ค(BFS ๋ฐ ์ค‘๋ ฅ ์ ์šฉ), ๋‹ค์Œ ์žฌ๊ท€๋กœ ๋„˜์–ด๊ฐ€๋ฉฐ ์ตœ๋Œ“๊ฐ’์„ ๊ฐฑ์‹ 

## 2. ์‹œ๊ฐ„ ๋ณต์žก๋„

**O(W^N * W * H)** โ€”

* ๊ตฌ์Šฌ์„ ๋–จ์–ด๋œจ๋ฆด ์—ด์„ ์„ ํƒํ•˜๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋Š” ์ตœ๋Œ€ **W^N**
* ๋งค ๊ฒฝ์šฐ๋งˆ๋‹ค ์—ฐ์‡„ ํญ๋ฐœ์„ ์ฒ˜๋ฆฌํ•˜๋Š” BFS์™€ ์ค‘๋ ฅ ์ž‘์šฉ ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋˜๋ฉฐ, ์ด๋Š” ๋ณด๋“œ์˜ ๋ชจ๋“  ์นธ์„ ํ•œ ๋ฒˆ์”ฉ ์ˆœํšŒํ•˜๋ฏ€๋กœ **O(W * H)**
Comment on lines +21 to +24

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

BFS ๋น„์šฉ์„ ๋ณต์žก๋„์— ๋ฐ˜์˜ํ•ด ์ฃผ์„ธ์š”.

_blast๋Š” ๋ฐฉ๋ฌธํ•œ ๋ฒฝ๋Œ๋งˆ๋‹ค 4 * (radius - 1)๊ฐœ ์œ„์น˜๋ฅผ ๊ฒ€์‚ฌํ•˜๋ฏ€๋กœ, R = ์ตœ๋Œ€ ๋ฒฝ๋Œ ๊ฐ’์œผ๋กœ ๋‘๋ฉด ์ „์ฒด ๋ณต์žก๋„๋Š” O(W^N * W * H * R)์ž…๋‹ˆ๋‹ค. R์ด ๋ฌธ์ œ ์ œ์•ฝ์ƒ ์ƒ์ˆ˜์ผ ๋•Œ๋งŒ ํ˜„์žฌ์˜ O(W^N * W * 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/yeseolee/5566-๋ฒฝ๋Œ` ๊นจ๊ธฐ.md around lines 21 - 24, ๋ณต์žก๋„ ์„ค๋ช…์„ ์‹ค์ œ
_blast์˜ ๋ฐ˜๋ณต ๊ตฌ์กฐ์— ๋งž๊ฒŒ ์ˆ˜์ •ํ•˜์„ธ์š”. ๋ฐฉ๋ฌธํ•œ ๋ฒฝ๋Œ๋งˆ๋‹ค ๋ฐ˜๊ฒฝ์— ๋น„๋ก€ํ•ด ์ตœ๋Œ€ 4 * (R - 1)๊ฐœ ์œ„์น˜๋ฅผ ๊ฒ€์‚ฌํ•˜๋ฏ€๋กœ, R์„ ์ตœ๋Œ€ ๋ฒฝ๋Œ
๊ฐ’์œผ๋กœ ์ •์˜ํ•˜๊ณ  ์ „์ฒด ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ O(W^N * W * H * R)๋กœ ๋ช…์‹œํ•˜์„ธ์š”. R์ด ๋ฌธ์ œ ์ œ์•ฝ์ƒ ์ƒ์ˆ˜์ธ ๊ฒฝ์šฐ์—๋งŒ ๊ธฐ์กด ํ‘œํ˜„์œผ๋กœ ๋‹จ์ˆœํ™”ํ•  ์ˆ˜
์žˆ์Œ์„ ๋ง๋ถ™์ด๊ณ , โ€œ๋ชจ๋“  ์นธ์„ ํ•œ ๋ฒˆ์”ฉ ์ˆœํšŒโ€ํ•œ๋‹ค๋Š” ์„ค๋ช…์€ ์ œ๊ฑฐํ•˜๊ฑฐ๋‚˜ ์ •ํ™•ํžˆ ์ˆ˜์ •ํ•˜์„ธ์š”.

Source: Path instructions


## 3. ๊ณต๊ฐ„ ๋ณต์žก๋„

**O(N * W * H)** โ€”

* ๋ฐฑํŠธ๋ž˜ํ‚น ์žฌ๊ท€ ํ˜ธ์ถœ ์ตœ๋Œ€ **N** ๊นŠ์ด
* ๊ฐ ์žฌ๊ท€ ๊นŠ์ด๋งˆ๋‹ค ๋ณด๋“œ์˜ ์ƒํƒœ๋ฅผ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•ด `prev_board` ๋ฐฐ์—ด(**W * H**)์„ ๋ณต์‚ฌ
* BFS ํƒ์ƒ‰ ์‹œ ์‚ฌ์šฉ๋˜๋Š” ํ์™€ ๋ฐฉ๋ฌธ ์ฒ˜๋ฆฌ์šฉ ์ง‘ํ•ฉ(Set)์ด ์ตœ๋Œ€ **W * H**

## 4. ํ•ต์‹ฌ ํ’€์ด ๋ฐฉ๋ฒ• โญ

* **๋ฐฐ์—ด 90๋„ ํšŒ์ „:** `board = [list(row) for row in zip(*board[::-1])]` ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด 2์ฐจ์› ๋ฐฐ์—ด์„ ์‹œ๊ณ„ ๋ฐฉํ–ฅ์œผ๋กœ ํšŒ์ „
* **์ค‘๋ ฅ ๊ตฌํ˜„:** ๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ฆฌํ—จ์…˜์„ ์ด์šฉํ•ด 0์ด ์•„๋‹Œ ๊ฐ’๋งŒ ์ถ”์ถœํ•˜๊ณ , ๊ธฐ์กด ๋ฐฐ์—ด์˜ ๊ธธ์ด์—์„œ ์ถ”์ถœํ•œ ๊ฐ’์˜ ๊ธธ์ด๋ฅผ ๋บ€ ๋งŒํผ 0์„ `extend`
* **๊ฐ€์ง€์น˜๊ธฐ:** ๋‚จ์€ ํšŸ์ˆ˜(`tries`)๊ฐ€ 0์ด ๋˜๊ฑฐ๋‚˜, ํ˜„์žฌ๊นŒ์ง€ ๊นฌ ๋ฒฝ๋Œ ์ˆ˜(`cnt`)๊ฐ€ ์ „์ฒด ๋ฒฝ๋Œ ์ˆ˜(`block_cnt`)์™€ ๋™์ผํ•ด์ง€๋ฉด ์กฐ๊ธฐ ์ข…๋ฃŒ
* **ํ—ˆ๊ณต ์ฒ˜๋ฆฌ:** ํŠน์ • ์—ด์— ๋ฒฝ๋Œ์ด ํ•˜๋‚˜๋„ ์—†๋Š” ๊ฒฝ์šฐ(ํ—ˆ๊ณต) ํ•ด๋‹น ์—ด์—์„œ์˜ ์ง„ํ–‰์„ ํŒจ์Šค

## 5. ์‹ค์ œ ์ฝ”๋“œ

```python
from collections import deque


def solution(n, w, h, board):
# ์‹œ๊ณ„ 90๋„ ํšŒ์ „
board = [list(row) for row in zip(*board[::-1])]
block_cnt = sum([1 for i in range(w) for j in range(h) if board[i][j] != 0])
max_break_cnt = 0
dx, dy = [0, 0, 1, -1], [1, -1, 0, 0]

def _blast(i, j):
nonlocal board
visited = set([(i, j)])
que = deque([(i, j)])

while que:
x, y = que.popleft()
radius = board[x][y]
board[x][y] = 0

if radius <= 1:
continue

for d in range(4):
for r in range(1, radius):
nx, ny = x + dx[d] * r, y + dy[d] * r
if not (0 <= nx < w and 0 <= ny < h):
continue
if (nx, ny) in visited:
continue
if board[nx][ny] == 0:
continue

visited.add((nx, ny))
que.append((nx, ny))

return len(visited)

def _gravity():
nonlocal board
for x in range(w):
arr = [board[x][y] for y in range(h) if board[x][y] != 0]
arr.extend([0] * (h - len(arr)))
board[x] = arr

def _backtracking(tries, cnt):
nonlocal max_break_cnt, board

if cnt == block_cnt or tries == 0:
max_break_cnt = max(max_break_cnt, cnt)
return

for x in range(w):
for y in range(h - 1, -1, -1):
if board[x][y] != 0:
prev_board = [row[:] for row in board]
cur_cnt = _blast(x, y)
_gravity()
_backtracking(tries - 1, cnt + cur_cnt)
board = prev_board
break
else:
# ํ—ˆ๊ณต
_backtracking(tries - 1, cnt)
Comment on lines +96 to +107

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 | ๐Ÿ”ต Trivial | โšก Quick win

๋นˆ ์—ด ์žฌ๊ท€ ํ˜ธ์ถœ์„ ํ•œ ๋ฒˆ์œผ๋กœ ํ•ฉ์ณ ์ฃผ์„ธ์š”.

๋นˆ ์—ด๋งˆ๋‹ค ๋ณด๋“œ ์ƒํƒœ๊ฐ€ ์ „ํ˜€ ๋ฐ”๋€Œ์ง€ ์•Š์€ ๋™์ผํ•œ _backtracking(tries - 1, cnt)๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. ๋นˆ ์—ด์ด ์—ฌ๋Ÿฌ ๊ฐœ๋ฉด ๋™์ผํ•œ ํƒ์ƒ‰์„ ์ค‘๋ณต ์ˆ˜ํ–‰ํ•˜๋ฏ€๋กœ, has_empty_column ํ”Œ๋ž˜๊ทธ๋กœ ๋นˆ ์—ด ๋ถ„๊ธฐ๋ฅผ ํ•œ ๋ฒˆ๋งŒ ์‹คํ–‰ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๊ฐœ์„  ์˜ˆ์‹œ
+        has_empty_column = False
         for x in range(w):
             for y in range(h - 1, -1, -1):
                 if board[x][y] != 0:
                     ...
                     board = prev_board
                     break
             else:
-                # ํ—ˆ๊ณต
-                _backtracking(tries - 1, cnt)
+                has_empty_column = True
+
+        if has_empty_column:
+            _backtracking(tries - 1, cnt)

๊ฒฝ๋กœ ์ง€์นจ์˜ SWEA ์‹œ๊ฐ„ ์ œํ•œ ๋ฐ ๋น„ํšจ์œจ ํƒ์ƒ‰ ์ ๊ฒ€ ์š”๊ตฌ๋ฅผ ์ ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ“ 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
for x in range(w):
for y in range(h - 1, -1, -1):
if board[x][y] != 0:
prev_board = [row[:] for row in board]
cur_cnt = _blast(x, y)
_gravity()
_backtracking(tries - 1, cnt + cur_cnt)
board = prev_board
break
else:
# ํ—ˆ๊ณต
_backtracking(tries - 1, cnt)
has_empty_column = False
for x in range(w):
for y in range(h - 1, -1, -1):
if board[x][y] != 0:
prev_board = [row[:] for row in board]
cur_cnt = _blast(x, y)
_gravity()
_backtracking(tries - 1, cnt + cur_cnt)
board = prev_board
break
else:
has_empty_column = True
if has_empty_column:
_backtracking(tries - 1, cnt)
๐Ÿค– 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/yeseolee/5566-๋ฒฝ๋Œ` ๊นจ๊ธฐ.md around lines 96 - 107, Update
_backtrackingโ€™s column iteration to track empty columns with a has_empty_column
flag and invoke _backtracking(tries - 1, cnt) only once when at least one column
is empty; keep non-empty column branching and board restoration unchanged.

Source: Path instructions


_backtracking(n, 0)
return block_cnt - max_break_cnt


T = int(input())
for test_case in range(1, T + 1):
N, W, H = map(int, input().split())
board = [list(map(int, input().split())) for _ in range(H)]
answer = solution(N, W, H, board)
print(f"#{test_case} {answer}")

```

---

### ๐Ÿง  ํšŒ๊ณ  (์„ ํƒ)

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

Heading ๋’ค์— ๋นˆ ์ค„์„ ์ถ”๊ฐ€ํ•ด ์ฃผ์„ธ์š”.

Markdownlint MD022 ๊ฒฝ๊ณ ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฏ€๋กœ ### ๐Ÿง  ํšŒ๊ณ  (์„ ํƒ) ๋‹ค์Œ์— ๋นˆ ์ค„์„ ์ถ”๊ฐ€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿงฐ Tools
๐Ÿช› markdownlint-cli2 (0.23.1)

[warning] 124-124: 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/yeseolee/5566-๋ฒฝ๋Œ` ๊นจ๊ธฐ.md at line 124, Update the Markdown
immediately after the โ€œ### ๐Ÿง  ํšŒ๊ณ  (์„ ํƒ)โ€ heading to include a blank line before
the following content, satisfying Markdownlint MD022.

Source: Linters/SAST tools

* ๋ฐฐ์—ด์„ ํšŒ์ „์‹œํ‚ค๋Š” ์•„์ด๋””์–ด๋ฅผ ์ ์šฉํ•˜๋ฉด ์ค‘๋ ฅ ์ฒ˜๋ฆฌ์™€ ๊ฐ™์€ ํŠน์ • ์ด๋™ ๋กœ์ง์ด ์‰ฌ์›Œ์ง‘๋‹ˆ๋‹ค.
Loading
Loading