Skip to content

Commit

Permalink
Merge pull request #19 from AlgoLeadMe/5-suhyun113
Browse files Browse the repository at this point in the history
5-suhyun113
  • Loading branch information
suhyun113 authored May 14, 2024
2 parents 79f09ec + 034ac61 commit 7d7e5c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion suhyun113/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
| 1์ฐจ์‹œ | 2024.03.25 | ๊ทธ๋ฆฌ๋”” | [์ฒด์œก๋ณต](https://school.programmers.co.kr/learn/courses/30/lessons/42862) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/2) |
| 2์ฐจ์‹œ | 2024.03.29 | ์ˆ˜ํ•™ | [์†Œ์ˆ˜ & ํŒฐ๋ฆฐ๋“œ๋กฌ](https://www.acmicpc.net/problem/1747) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/9) |
| 3์ฐจ์‹œ | 2024.04.02 | ๊ทธ๋ฆฌ๋”” | [๊ฑฐ์Šค๋ฆ„๋ˆ](https://www.acmicpc.net/problem/14916) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/12) |
| 4์ฐจ์‹œ | 2024.04.06 | DP | [ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜ 5](https://www.acmicpc.net/problem/10870) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/16) |
| 4์ฐจ์‹œ | 2024.04.06 | DP | [ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜ 5](https://www.acmicpc.net/problem/10870) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/16) |
| 5์ฐจ์‹œ | 2024.04.10 | ์Šคํƒ | [ํฌ๋ ˆ์ธ ์ธํ˜• ๋ฝ‘๊ธฐ ๊ฒŒ์ž„](https://school.programmers.co.kr/learn/courses/30/lessons/64061) | [#19](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/19) |
24 changes: 24 additions & 0 deletions suhyun113/์Šคํƒ/5-suhyun113.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def solution(board, moves):
answer = 0
basket = [float("inf")] # board๋ฐฐ์—ด์—์„œ ๋ฝ‘์€ ์ธํ˜•๋“ค์„ ๋„ฃ๋Š” ๋ฐ”๊ตฌ๋‹ˆ

N = len(board) # board 2์ฐจ์› ๋ฐฐ์—ด์€ N*N์ด๋ฏ€๋กœ, board์˜ ํ–‰ ๋˜๋Š” ์—ด์˜ ๊ธธ์ด๋ฅผ N์œผ๋กœ ๋ฐ›์Œ.

# moves 1์ฐจ์› ๋ฐฐ์—ด์— ์žˆ๋Š” ์š”์†Œ์— ๋”ฐ๋ผ ์–ด๋–ค ์—ด์˜ ์ธํ˜•์„ ๋ฝ‘์„ ์ง€ ์ •ํ•จ.
for move in moves: #[1 5 3 5 1 2 1 4]
move -= 1 # 1๋ฒˆ์งธ๊ฐ€ ์‹ค์ œ๋กœ board๋ฐฐ์—ด์—์„œ๋Š” 0๋ฒˆ์งธ ์ด๋ฏ€๋กœ, ๊ฐ ์š”์†Œ๋งˆ๋‹ค 1์”ฉ ๋นผ์คŒ.
doll = 0 # ์ธํ˜•์ด ๋น„์–ด์žˆ๋‹ค๊ณ  ๊ฐ€์ • -> 0์œผ๋กœ ์ดˆ๊ธฐํ™”

for i in range(N):
if board[i][move] != 0: # ์—ด์€ move๋กœ ์ •ํ•ด์ ธ ์žˆ๊ณ , ํ–‰์ด i๋กœ ๊ณ„์† ๋ณ€ํ•จ.
doll = board[i][move] # 0์ด ์•„๋‹ˆ๋ผ๋ฉด, ์ธํ˜•์ด ์žˆ๋Š” ๊ฒƒ์ด๋ฏ€๋กœ, ์ธํ˜•์˜ ๊ฐ’์„ ๋ณ€๊ฒฝ
board[i][move] = 0
break

if doll != 0: # ์ธํ˜•์ด ๋น„์–ด์žˆ์ง€ ์•Š์•„์„œ doll์— ์ƒˆ๋กœ์šด ์ธํ˜•์˜ ๊ฐ’์ด ๋“ค์–ด๊ฐ”์„ ๋•Œ,
if basket[-1] == doll: # ๋ฐ”๊ตฌ๋‹ˆ ๊ฐ€์žฅ ์œ„์— ๋‹ด๊ธด ์ธํ˜•๊ณผ ์ƒˆ๋กœ ๋ฝ‘์€ ์ธํ˜•์ด ๊ฐ™๋‹ค๋ฉด
basket.pop() # ๋ฐ”๊ตฌ๋‹ˆ ๊ฐ€์žฅ ์œ„์˜ ์ธํ˜• ์ œ๊ฑฐ
answer += 2 # ๊ฐ™์€ ์ธํ˜•์ด ๋ฐ”๊ตฌ๋‹ˆ์— ๋‹ด๊ฒผ์œผ๋ฏ€๋กœ, 2๊ฐœ์˜ ์ธํ˜•์ด ํ„ฐ์ง
else:
basket.append(doll) # ๋ฐ”๊ตฌ๋‹ˆ์˜ ๊ฐ€์žฅ ์œ„์˜ ์ธํ˜•๊ณผ ๊ฐ™์€ ์ธํ˜•์ด ์•„๋‹ˆ๋ผ๋ฉด, doll์„ ์ƒˆ๋กœ ๋ฐ”๊ตฌ๋‹ˆ์— ์ถ”๊ฐ€ํ•˜๊ธฐ
return answer

0 comments on commit 7d7e5c3

Please sign in to comment.