Skip to content

Commit

Permalink
Merge pull request #169 from AlgoLeadMe/41-pknujsp
Browse files Browse the repository at this point in the history
41-pknujsp
  • Loading branch information
MunbinLee authored May 3, 2024
2 parents 0d347be + b13d92f commit c124bfa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pknujsp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@
| 37์ฐจ์‹œ | 2024.03.04 | ๊ตฌํ˜„ | [n+1 ์นด๋“œ๊ฒŒ์ž„](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#149](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/149) |
| 38์ฐจ์‹œ | 2024.03.08 | BRUTE_FORCE | [์ž๋ฌผ์‡ ์™€ ์—ด์‡ ](https://school.programmers.co.kr/learn/courses/30/lessons/60059) | [#154](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/154) |
| 39์ฐจ์‹œ | 2024.03.19 | ํ | [๋””์Šคํฌ ์ปจํŠธ๋กค๋Ÿฌ](https://school.programmers.co.kr/learn/courses/30/lessons/42627) | [#163](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/163) |
| 40์ฐจ์‹œ | 2024.03.22 | ๊ทธ๋ฆฌ๋”” | [์„ผ์„œ](https://www.acmicpc.net/problem/2212) | [#168](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/168) |
| 40์ฐจ์‹œ | 2024.03.22 | ๊ทธ๋ฆฌ๋”” | [์„ผ์„œ](https://www.acmicpc.net/problem/2212) | [#168](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/168) |
| 41์ฐจ์‹œ | 2024.03.25 | ๋‹ค์ต์ŠคํŠธ๋ผ | [์•Œ๊ณ ์ŠคํŒŸ](https://www.acmicpc.net/problem/1261) | [#169](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/169) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from heapq import *
from sys import *

C, R = map(int, stdin.readline().split())
arr = [list(map(int, list(stdin.readline().strip()))) for _ in range(R)]

drc = ((1,0),(-1,0),(0,1),(0,-1))
visited = [[False] * C for _ in range(R)]
heap = [(0, 0, 0)]
target_r = R - 1
target_c = C - 1

while heap:
cost, r, c = heappop(heap)

if r == target_r and c == target_c:
print(cost)
break
if visited[r][c]:
continue

visited[r][c] = True

for dr, dc in drc:
nr = r + dr
nc = c + dc

if not 0 <= nr < R or not 0 <= nc < C:
continue
if visited[nr][nc]:
continue

heappush(heap, (cost + arr[nr][nc], nr, nc))

0 comments on commit c124bfa

Please sign in to comment.