Skip to content

Commit c124bfa

Browse files
authored
Merge pull request #169 from AlgoLeadMe/41-pknujsp
41-pknujsp
2 parents 0d347be + b13d92f commit c124bfa

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

pknujsp/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@
4141
| 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) |
4242
| 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) |
4343
| 39차시 | 2024.03.19 || [디스크 컨트롤러](https://school.programmers.co.kr/learn/courses/30/lessons/42627) | [#163](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/163) |
44-
| 40차시 | 2024.03.22 | 그리디 | [센서](https://www.acmicpc.net/problem/2212) | [#168](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/168) |
44+
| 40차시 | 2024.03.22 | 그리디 | [센서](https://www.acmicpc.net/problem/2212) | [#168](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/168) |
45+
| 41차시 | 2024.03.25 | 다익스트라 | [알고스팟](https://www.acmicpc.net/problem/1261) | [#169](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/169) |
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from heapq import *
2+
from sys import *
3+
4+
C, R = map(int, stdin.readline().split())
5+
arr = [list(map(int, list(stdin.readline().strip()))) for _ in range(R)]
6+
7+
drc = ((1,0),(-1,0),(0,1),(0,-1))
8+
visited = [[False] * C for _ in range(R)]
9+
heap = [(0, 0, 0)]
10+
target_r = R - 1
11+
target_c = C - 1
12+
13+
while heap:
14+
cost, r, c = heappop(heap)
15+
16+
if r == target_r and c == target_c:
17+
print(cost)
18+
break
19+
if visited[r][c]:
20+
continue
21+
22+
visited[r][c] = True
23+
24+
for dr, dc in drc:
25+
nr = r + dr
26+
nc = c + dc
27+
28+
if not 0 <= nr < R or not 0 <= nc < C:
29+
continue
30+
if visited[nr][nc]:
31+
continue
32+
33+
heappush(heap, (cost + arr[nr][nc], nr, nc))

0 commit comments

Comments
 (0)