-
Notifications
You must be signed in to change notification settings - Fork 0
[W01] Suyoung-Min - SWEA 1767๋ฒ #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
240 changes: 240 additions & 0 deletions
240
studies/week-01/Suyoung-Min/1767-ํ๋ก์ธ์์ฐ๊ฒฐํ๊ธฐ.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,240 @@ | ||
| # [SWEA 1767] ํ๋ก์ธ์ ์ฐ๊ฒฐํ๊ธฐ | ||
|
|
||
| | ํญ๋ชฉ | ๋ด์ฉ | | ||
| |:---|:---| | ||
| | ๐ ๋ฌธ์ | https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV4suNtaXFEDFAUf | | ||
| | ๐ ์ฃผ์ | ์์ ํ์ ยท ๋ฐฑํธ๋ํน ยท ๊ฐ์ง์น๊ธฐ | | ||
| | ๐๏ธ ๋์ด๋ | ๋ชจ์ SW ์ญ๋ํ ์คํธ ์ํ๋ฌธ์ | | ||
| | โฑ๏ธ ์์ ์๊ฐ | 1์๊ฐ ๋ฐ | | ||
| | ๐ ๋ค์ ํ๊ธฐ | ์ | | ||
|
|
||
| --- | ||
|
|
||
| ## 1. ์ ๊ทผ ๋ฐฉ๋ฒ | ||
|
|
||
| `N ร N` ๊ฒฉ์(7 โค N โค 12)์์ ๊ฐ ์ฝ์ด๋ฅผ **์/ํ/์ข/์ฐ ์ค ํ ๋ฐฉํฅ์ผ๋ก ์ง์ ์ ์ ์ ๋ป์ด** ๊ฒฉ์ ๋ฐ(์ ์)๊น์ง ์ฐ๊ฒฐํ๋ค. | ||
| ๋ชฉํ๋ **์ฐ๊ฒฐํ ์ฝ์ด ์๋ฅผ ์ต๋ํ**ํ๊ณ , ๊ทธ์ค์์ **์ ์ ๊ธธ์ด ํฉ์ ์ต์ํ**ํ๋ ๊ฒ. | ||
|
|
||
| ๋จผ์ ๋ ๊ฐ์ง๋ฅผ ์ ๋ฆฌํ๊ณ ์์ํ๋ค. | ||
|
|
||
| - **๊ฐ์ฅ์๋ฆฌ ์ฝ์ด๋ ์ด๋ฏธ ์ ์์ ์ฐ๊ฒฐ**๋์ด ์์ผ๋ฏ๋ก ํ์ ๋์์์ ์ ์ธํ๋ค โ ๋ด๋ถ `1 โค y, x โค N-2`๋ง `cores`์ ๋ด๋๋ค. | ||
| - ๋ด๋ถ ์นธ์ ์ต๋ `10 ร 10`์ด์ง๋ง ๋ฌธ์ ์กฐ๊ฑด์ **์ฝ์ด๋ ์ต๋ 12๊ฐ**๋ค. | ||
|
|
||
| ๊ทธ๋ฆฌ๋๋ DP๋ฅผ ์ ๊น ๊ณ ๋ฏผํ์ง๋ง ๊ณง ์ ์๋ค. **์ ์ ๋ผ๋ฆฌ ์๋ก๋ฅผ ๊ฐ๋ก๋ง๊ธฐ ๋๋ฌธ์ ๊ฐ ์ฝ์ด์ ์ ํ์ด ๋ ๋ฆฝ์ ์ด์ง ์๋ค.** | ||
| A ์ฝ์ด๋ฅผ ์๋ก ๋ป์ผ๋ฉด B ์ฝ์ด์ ์ค๋ฅธ์ชฝ ๊ฒฝ๋ก๊ฐ ๋งํ๋ ์์ด๋ผ, ๋ถ๋ถ ์ต์ ํด๋ฅผ ํฉ์ณ๋ ์ ์ฒด ์ต์ ํด๊ฐ ์ ๋๋ค. | ||
|
|
||
| ๊ฒฐ๊ตญ **์ฝ์ด ํ๋๋น ์ ํ์ง 5๊ฐ์ง(์ยทํยท์ขยท์ฐยท์ฐ๊ฒฐ ์ ํจ)** ๋ฅผ ๋ชจ๋ ์๋ํ๋ ๋ฐฑํธ๋ํน์ผ๋ก ๊ฐ๋ค. | ||
| ํ์ ํธ๋ฆฌ๋ ์ต๋ `5^12 โ 2.4์ต`์ด๋ผ ๊ทธ๋๋ก๋ ํ์ด์ฌ์์ ๊ฐ๋น์ด ์ ๋๋ฏ๋ก, **๊ฐ์ง์น๊ธฐ๋ฅผ ๋ฐ๋์ ๋ถ์ฌ์ผ ํ๋ค.** | ||
|
|
||
| **๋งํ๋ ์ง์ โ ๋ต์ด ๊ณ์ 0์ผ๋ก ๋์๋ค.** | ||
|
|
||
| ```python | ||
| best_core = max(best_core, cnum) # โ | ||
| best_len = min(best_len, line_length) | ||
| ``` | ||
|
|
||
| ๋ ๊ฐ์ **๋ ๋ฆฝ์ ์ผ๋ก** ๊ฐฑ์ ํ ๊ฒ ์์ธ์ด์๋ค. ํ์ ํธ๋ฆฌ์๋ "๋ชจ๋ ์ฝ์ด๋ฅผ ํจ์คํ๋ ๊ฒฝ๋ก"๊ฐ ๋ฐ๋์ ํฌํจ๋๊ณ , | ||
| ๊ทธ ๋ฆฌํ์์ `cnum=0, line_length=0`์ด ๋ค์ด์ค๋ฉด์ `best_len`์ด ์ฆ์ 0์ผ๋ก ๊ณ ์ ๋์ด ๋ฒ๋ ธ๋ค. | ||
| ์ด ๋ฌธ์ ๋ `(์ฝ์ด ์ ์ต๋, ๊ธธ์ด ์ต์)`๋ผ๋ **์ฌ์ ์(lexicographic) ๋น๊ต**์ด๋ฏ๋ก ๋ ๊ฐ์ ๋ฌถ์ด์ ๊ฐฑ์ ํด์ผ ํ๋ค. | ||
|
|
||
| ## 2. ์๊ฐ ๋ณต์ก๋ | ||
|
|
||
| **O(5^C ยท N)** โ C = ๋ด๋ถ ์ฝ์ด ์(โค 12), N = ๊ฒฉ์ ํ ๋ณ(โค 12). | ||
|
|
||
| - ํ์ ํธ๋ฆฌ ๋ ธ๋ ์: ์ฝ์ด๋น 5๊ฐ์ง ์ ํ โ ์ต๋ `5^C` | ||
| - ๋ ธ๋ 1๊ฐ๋น ๋น์ฉ: 4๋ฐฉํฅ ร ๊ด์ ์ํ `O(N)` โ `O(N)` | ||
| - ์ํ์ `5^12 ร 12 โ 29์ต`์ด์ง๋ง, **์๋ ๋ ๊ฐ์ง ๊ฐ์ง์น๊ธฐ๊ฐ ์ค์ง ํ์๋์ ์ค์ธ๋ค.** | ||
|
|
||
|
|
||
| ## 3. ๊ณต๊ฐ ๋ณต์ก๋ | ||
|
|
||
| **O(Nยฒ)** โ ๊ฒฉ์ `Nยฒ`๊ฐ ์ง๋ฐฐ์ . ์ฝ์ด ์ขํ ๋ฆฌ์คํธ `O(C)`, ์ฌ๊ท ๊น์ด `O(C)`. | ||
|
|
||
| ๋ณ๋์ `visited` ๋ฐฐ์ด์ ๋ง๋ค์ง ์๊ณ **๊ฒฉ์ ์์ฒด์ ์ ์ ์ `2`๋ก ๊ธฐ๋กํ๋ค๊ฐ ๋ณต์**ํ๋ฏ๋ก ์ถ๊ฐ ๋ฉ๋ชจ๋ฆฌ๊ฐ ์๋ค. | ||
|
|
||
| ## 4. ํต์ฌ ํ์ด ๋ฐฉ๋ฒ โญ | ||
|
|
||
| **โ ์ฌ์ ์ ๋น๊ต โ ์ด ๋ฌธ์ ์ต๋์ ํจ์ ** | ||
|
|
||
| `max`/`min`์ ๋ฐ๋ก ์ฐ๋ฉด ์ ๋๋ค. ์ฝ์ด ์๊ฐ ๊ฐฑ์ ๋๋ ์๊ฐ **๊ธฐ์กด `best_len`์ ๋ค๋ฅธ ์ฝ์ด ์์์ ๋์จ ๊ฐ**์ด๋ฏ๋ก ๋ฒ๋ ค์ผ ํ๋ค. | ||
|
|
||
| ```python | ||
| if cnum > best_core: | ||
| best_core, best_len = cnum, line_length # ๊ฐ์ ๊ฐฑ์ โ ๊ธธ์ด๋ ๋ฆฌ์ (๋์ ) | ||
| elif cnum == best_core: | ||
| best_len = min(best_len, line_length) # ๋์ ์ผ ๋๋ง min | ||
| ``` | ||
|
|
||
| `cnum > best_core`์ธ๋ฐ `min`์ ์ฐ๋ฉด, ์ฝ์ด๋ฅผ ์ ๊ฒ ์ฐ๊ฒฐํ ๊ฒฝ๋ก์ ์งง์ ๊ธธ์ด๊ฐ ๊ทธ๋๋ก ์ด์๋จ์ ์ค๋ต์ด ๋๋ค. | ||
| ์ฝ์ด๋ฅผ ๋ ์ฐ๊ฒฐํ ์๋ก ์ ์ ๋ ์งง์ผ๋ ์ด ์ํฉ์ ์์ธ๊ฐ ์๋๋ผ **๊ธฐ๋ณธ๊ฐ**์ ๊ฐ๊น๋ค. | ||
|
|
||
| **โก ๊ฐ์ง์น๊ธฐ 2์ข ** | ||
|
|
||
| ```python | ||
| rest = len(cores) - cidx # ์์ง ๊ฒฐ์ ์ ๋ ์ฝ์ด ์ | ||
|
|
||
| if cnum + rest < best_core: # ๊ฐ์ ์ปท | ||
| return | ||
| if cnum + rest == best_core and line_length >= best_len: # ๊ธธ์ด ์ปท | ||
| return | ||
| ``` | ||
|
|
||
| - **๊ฐ์ ์ปท**: ๋จ์ ์ฝ์ด๋ฅผ ์ ๋ถ ์ฐ๊ฒฐํด๋ ์ต๊ณ ๊ธฐ๋ก์ ๋ชป ๋ฏธ์น๋ฉด ๋ณผ ํ์ ์์. | ||
| - **๊ธธ์ด ์ปท**: ์ ์ ๊ธธ์ด๋ **๋จ์กฐ ์ฆ๊ฐ๋ง** ํ๋ฏ๋ก, ๋์ ์ด ์ต์ ์ธ๋ฐ ์ด๋ฏธ ๊ธธ์ด๊ฐ ๋ฐ๋ ธ์ผ๋ฉด ๋ณผ ํ์ ์์. | ||
| ์ด ์ปท ํ๋๋ก ์ต์ ์ผ์ด์ค๊ฐ ์ฝ 6๋ฐฐ ๋นจ๋ผ์ก๋ค(0.09์ด โ 0.015์ด). | ||
|
|
||
| **โข `rest`์ ํ์ฌ `cidx`๋ฅผ ํฌํจ์์ผ์ผ ํ๋ค** | ||
|
|
||
| `rest = len(cores) - cidx`์ด์ง `len(cores) - 1 - cidx`๊ฐ ์๋๋ค. | ||
| `backtrack(cidx, cnum, ...)` ์์ ์์ `cnum`์ **์ธ๋ฑ์ค 0 ~ cidx-1**๋ง ์ผ ๊ฐ์ด๊ณ , `cidx`๋ ์์ง ๋ฏธ๊ฒฐ์ = **์์ผ๋ก ์ฐ๊ฒฐ ๊ฐ๋ฅํ ํ๋ณด**๋ค. | ||
|
|
||
| ``` | ||
| ์ธ๋ฑ์ค: 0 1 2 | 3 4 5 6 (len=7, cidx=3) | ||
| โโ๊ฒฐ์ ์๋ฃโโ โโโโ๋ฏธ๊ฒฐ์ โโโโ | ||
| cnum์ด ์ rest = 7-3 = 4 | ||
| ``` | ||
|
|
||
| `rest`๋ฅผ 1 ์๊ฒ ์ก์ผ๋ฉด ์กฐ๊ฑด์ด `cnum + rest โค best_core`๊ฐ ๋์ด **์ต๊ณ ๊ธฐ๋ก๊ณผ ๋์ ์ ๋ง๋ค ์ ์๋ ๊ฒฝ๋ก๊น์ง ์๋ผ๋ธ๋ค.** | ||
| ์ฝ์ด ๊ฐ์๋ ์ฌ์ ํ ๋ง๊ณ **๊ธธ์ด๋ง ํ๋ฆฌ๊ธฐ ๋๋ฌธ์** ๋์ ์ ์ ๋๋ ๋ฒ๊ทธ๋ค. (๋ธ๋ฃจํธํฌ์ค ๋์กฐ ์ 300๊ฐ ์ค 71๊ฐ ๋ถ์ผ์น) | ||
|
|
||
| **โฃ ์ ์ ๋งํน์ ๊ฒฉ์์ ์ง์ , ๋ณต์์ ๋ฌด์กฐ๊ฑด ์์ ** | ||
|
|
||
| ์ ์ ์ `2`๋ก ๊ธฐ๋กํ๋ฉด ์ดํ ์ถฉ๋ ๊ฒ์ฌ๊ฐ `grid[ny][nx] != 0` **ํ ์ค๋ก ํต์ผ**๋๋ค. ์ฝ์ด(`1`)๋ ๋ค๋ฅธ ์ ์ (`2`)์ด๋ ๋๊ฐ์ด ์ฅ์ ๋ฌผ์ด๊ธฐ ๋๋ฌธ. | ||
|
|
||
| ๋ณต์ํ ๋ "๋ด ์ ์ ์ด ๋ง๋์ง" ํ์ธํ ํ์๊ฐ ์๋ค๋ ์ ์ด ์ค์ํ๋ค. | ||
| **์ถฉ๋ ์์ด ๊ฒฉ์ ๋ฐ๊น์ง ๋ป์ ๊ฒฝ๋ก๋ง ๋งํน**ํ์ผ๋ฏ๋ก ๊ทธ ๊ด์ ์์ ์นธ์ ์ ๋ถ ๋ด ๊ฒ์ด๊ณ , | ||
| ํ์ ์ฌ๊ท๋ ์๊ธฐ๊ฐ ์น ํ ๊ฑธ ๋ฐ๋์ ๋๋๋ฆฌ๊ณ ๋์์ค๊ธฐ ๋๋ฌธ์ ๊ทธ๋ฅ `0`์ผ๋ก ๋ฐ๋ฉด ๋๋ค. | ||
|
|
||
| ## 5. ์ค์ ์ฝ๋ | ||
|
|
||
| ```python | ||
| T = int(input()) | ||
| # ์ฌ๋ฌ๊ฐ์ ํ ์คํธ ์ผ์ด์ค๊ฐ ์ฃผ์ด์ง๋ฏ๋ก, ๊ฐ๊ฐ์ ์ฒ๋ฆฌํฉ๋๋ค. | ||
| for test_case in range(1, T + 1): | ||
|
|
||
| n = int(input()) | ||
|
|
||
| grid = [ list((map(int, input().split()))) for _ in range(n)] | ||
|
|
||
| cores = [] # ์ฝ์ด ์ขํ ์ ๋ณด | ||
|
|
||
| best_core, best_len = 0, int(1e10) # ์ฝ์ด ๊ฐ์ ๋ง์์๋ก, ์ ์ ๊ธธ์ด ์งง์์๋ก | ||
|
|
||
| d = [(-1, 0), (1, 0), (0, -1), (0 , 1)] # ์ ํ ์ข ์ฐ ๋ฐฉํฅ | ||
|
|
||
| # ์ ์ off ์ธ ์ฝ์ด ์ขํ ์ ์ฅ (๊ฐ์ฅ์๋ฆฌ๋ ์ด๋ฏธ ์ฐ๊ฒฐ๋์ด ์์ผ๋ฏ๋ก ์ ์ธ) | ||
| for y in range(1, n-1): | ||
| for x in range(1, n-1): | ||
| if grid[y][x]: cores.append((y, x)) | ||
|
|
||
|
|
||
| def backtrack(cidx, cnum, line_length): # ํ์ฌ ๋ณด๊ณ ์๋ ์ฝ์ด, ์ฐ๊ฒฐ๋ ์ฝ์ด ๊ฐ์, ์ ์ ๊ธธ์ด | ||
| global best_core, best_len | ||
|
|
||
| if cidx >= len(cores): # ์ฝ์ด ๋ค ํ์ํ์ผ๋ฉด | ||
| if cnum > best_core: | ||
| best_core, best_len = cnum, line_length # ๊ฐ์ ๊ฐฑ์ -> ๊ธธ์ด ๋ฆฌ์ | ||
| elif cnum == best_core: | ||
| best_len = min(best_len, line_length) # ๋์ ์ผ ๋๋ง ๊ธธ์ด ๋น๊ต | ||
| return | ||
|
|
||
| # ๊ฐ์ง์น๊ธฐ 1 - ๋จ์ ์ฝ์ด ๊ธฐ์ค | ||
| # ๋จ์ ๊ฑธ ๋ค ์ฐ๊ฒฐํด๋ ์ต๊ณ ๊ธฐ๋ก์ ๋ชป ๋ฏธ์น๋ฉด ์ปท | ||
|
|
||
| rest = len(cores) - cidx # cidx ๋ ์์ง ๋ฏธ๊ฒฐ์ ์ด๋ฏ๋ก ํฌํจ | ||
|
|
||
| if cnum + rest < best_core: return | ||
|
|
||
| # ๊ฐ์ง์น๊ธฐ 2 - ํ์ฌ ์ ์ ๊ธฐ์ค | ||
| # ๊ฐ์ ๋์ ์ด ์ต์ ์ธ๋ฐ ๊ธธ์ด๊ฐ ์ด๋ฏธ ๋ฐ๋ ธ์ผ๋ฉด ์ปท (๊ธธ์ด๋ ๋์ด๋๊ธฐ๋ง ํจ) | ||
|
|
||
| if cnum + rest == best_core and line_length >= best_len: return | ||
|
|
||
|
|
||
| # ํ์ฌ ์ฝ์ด ํ์ ํ๋ ๋ฃจํธ and ์ํ๋ ๋ฃจํธ | ||
|
|
||
| # 1. ์ํ์ข์ฐ ์ ์ ๋ป๊ธฐ | ||
|
|
||
| cy, cx = cores[cidx] # ํ์ฌ ์ฝ์ด ์์น | ||
|
|
||
| for dy, dx in d: | ||
| # ํด๋น ๋ฐฉํฅ์ผ๋ก ์ ์ ๋ป๊ธฐ | ||
| # ์ ์ ๊ฒฝ๋ก ๊ฒน์นจ ํ์ธ | ||
|
|
||
| cover_flag = False | ||
| cur_line_length = 0 | ||
|
|
||
| ny, nx = cy, cx | ||
|
|
||
| while True: | ||
| ny += dy | ||
| nx += dx | ||
|
|
||
| # ๋งต ๋ฐ์ด๋ฉด -> ์ ์ ์ฐ๊ฒฐ ์ฑ๊ณต -> ๋ฐ๋ณต๋ฌธ ํ์ถ | ||
| if ny < 0 or ny >= n or nx < 0 or nx >= n: break | ||
|
|
||
| if grid[ny][nx] != 0: # ๋น๊ณต๊ฐ์ด ์๋๋ฉด (์ฝ์ด ๋๋ ๋ค๋ฅธ ์ ์ ) | ||
| cover_flag = True # ๊ฒน์นจ | ||
| break | ||
|
|
||
| # ๋น๊ณต๊ฐ์ด๋ฉด | ||
| cur_line_length += 1 # ์ ์ ๊ธธ์ด + 1 | ||
|
|
||
| if not cover_flag: # ์๊ฒน์น๋ฉด | ||
| # ์ ์ ๋ฐฉ๋ฌธ์ฒ๋ฆฌ grid[y][x] = 2 | ||
|
|
||
| ny, nx = cy, cx | ||
|
|
||
| while True: | ||
| ny += dy | ||
| nx += dx | ||
|
|
||
| if ny < 0 or ny >= n or nx < 0 or nx >= n: break | ||
|
|
||
| grid[ny][nx] = 2 # ์ ์ ๋ฐฉ๋ฌธ ์ฒ๋ฆฌ 2 | ||
|
|
||
| backtrack(cidx + 1, cnum + 1, line_length + cur_line_length) | ||
|
|
||
| # ๋ฐฑํธ๋ํน ์งํ ํ ์ ์ ๊ฒฝ๋ก 0์ผ๋ก ์ด๊ธฐํ | ||
|
|
||
| ny, nx = cy, cx | ||
|
|
||
| while True: | ||
| ny += dy | ||
| nx += dx | ||
|
|
||
| if ny < 0 or ny >= n or nx < 0 or nx >= n: break | ||
|
|
||
| grid[ny][nx] = 0 # ๋ฐฉ๋ฌธ ๊ฒฝ๋ก 2 ์ 0 ์ผ๋ก ๋ค์ ์ด๊ธฐํ | ||
|
|
||
| # 2. ํ์ฌ ์ฝ์ด ํจ์ค | ||
|
|
||
| backtrack(cidx+1, cnum, line_length) | ||
|
|
||
|
|
||
| backtrack(0, 0, 0) | ||
|
|
||
| print('#'+str(test_case), best_len) | ||
| ``` | ||
|
|
||
|
|
||
| --- | ||
|
|
||
| ### ๐ง ํ๊ณ | ||
|
|
||
| - **"์ต๋ํ ํ ์ต์ํ" ์ ํ์ ๋ ๊ฐ์ ํํ์ฒ๋ผ ๋ฌถ์ด์ ๋น๊ตํ๋ค.** `max`/`min`์ ๋ฐ๋ก ์ฐ๋ฉด ์๋ก ๋ค๋ฅธ ์กฐ๊ฑด์์ ๋์จ ๊ฐ์ด ์์ธ๋ค. ๋ค์์ ๊ฐ์ ์ ํ(์ต๋ ์ ์ ์ค ์ต์ ์ด๋ ๋ฑ)์ ๋ง๋๋ฉด ๋ฆฌํ ๊ฐฑ์ ๋ก์ง๋ถํฐ ๋จผ์ ํ์ ํ๊ณ ์์ํ์. | ||
| - **๊ฐ์ง์น๊ธฐ๋ "์ด ๊ฒฝ๋ก๊ฐ ์์ผ๋ก ์ต์ ์ ๋์ด์ค ์ ์๋๊ฐ"๋ฅผ ์ํ์ผ๋ก ํ๋จํ๋ค.** ๊ฐ์๋ `ํ์ฌ + ๋จ์ ๊ฐ์`๊ฐ ์ํ์ด๊ณ , ๊ธธ์ด๋ ๋จ์กฐ ์ฆ๊ฐ๋ผ `ํ์ฌ ๊ฐ`์ด ํํ์ด๋ค. ์ํ/ํํ ๋ฐฉํฅ๋ง ์ ํํ ์ก์ผ๋ฉด ๊ธฐ๊ณ์ ์ผ๋ก ๋ง๋ค ์ ์๋ค. | ||
| - **์์ง ๊ฒฐ์ ์ ํ ์์๋ฅผ `rest`์ ํฌํจ์ํค๋์ง ํ์ธํ๋ ์ต๊ด.** ๋ง์ง๋ง ์ธ๋ฑ์ค(`cidx == len-1`)๋ฅผ ๋์ ํด์ `rest == 1`์ด ๋์ค๋์ง ๋ณด๋ฉด 1์ด ๋ง์ ๊ฒ์ฆ๋๋ค. | ||
| - **๊ฐ์ ์ฌ์ง (๋ฆฌ๋ทฐ ๋ฐ๊ณ ์ถ์ ๋ถ๋ถ)**: ์ง๊ธ ์ฝ๋๋ ๋ฐฉํฅ๋ง๋ค while ๋ฌธ์ด 3๊ฐ(๊ฒ์ฌ / ๋งํน / ๋ณต์) ๋ฐ๋ณต๋๋ค. ์ฒซ ์ํ์์ ์ง๋๊ฐ ์ขํ๋ฅผ ๋ฆฌ์คํธ๋ก ๋ชจ์๋๋ฉด ๋๋จธ์ง ๋ ๋ฒ์ ๊ทธ ๋ฆฌ์คํธ๋ง ํ์ผ๋ฉด ๋์ด while 3๊ฐ โ ํจ์ 1๊ฐ + `for` 2์ค๋ก ์ค์ด๋ ๋ค. `cover_flag`์ `cur_line_length`๋ ๊ฐ๊ฐ `None` ๋ฐํ๊ณผ `len(cells)`๋ก ๋์ฒด ๊ฐ๋ฅ. | ||
|
|
||
| ```python | ||
| def stretch(cy, cx, dy, dx): | ||
| """๋งต ๋ฐ๊น์ง ๋ป์ผ๋ฉด ์ง๋๊ฐ ์นธ ๋ชฉ๋ก, ๋งํ๋ฉด None""" | ||
| cells = [] | ||
| y, x = cy + dy, cx + dx | ||
| while 0 <= y < n and 0 <= x < n: | ||
| if grid[y][x]: return None | ||
| cells.append((y, x)) | ||
| y += dy; x += dx | ||
| return cells | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
์ฝ๋ ํ์ค์ ์ธ์ด ํ๊ทธ๋ฅผ ์ถ๊ฐํ์ธ์.
ASCII ์ธ๋ฑ์ค ๋ค์ด์ด๊ทธ๋จ์ด๋ฏ๋ก
textํ๊ทธ๋ฅผ ์ฌ์ฉํ๋ฉด Markdown lint ๊ฒฝ๊ณ (MD040)๋ฅผ ํด์ํ ์ ์์ต๋๋ค.์์ ์์
๐ Committable suggestion
๐งฐ Tools
๐ช markdownlint-cli2 (0.23.0)
[warning] 91-91: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
๐ค Prompt for AI Agents
Sources: Path instructions, Linters/SAST tools