Skip to content

Commit

Permalink
2024-05-22
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed May 22, 2024
1 parent 8da6d44 commit 5fe64aa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@
| 53์ฐจ์‹œ | 2024.05.09 | ๋ฐฑํŠธ๋ž˜ํ‚น | <a href="https://www.acmicpc.net/problem/12100">2048 (Easy)</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/184
| 54์ฐจ์‹œ | 2024.05.14 | ๋‹ค์ต์ŠคํŠธ๋ผ | <a href="https://www.acmicpc.net/problem/9370">๋ฏธํ™•์ธ ๋„์ฐฉ์ง€</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/185
| 55์ฐจ์‹œ | 2023.05.18 | ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ | <a href="https://www.acmicpc.net/problem/4195">์นœ๊ตฌ ๋„คํŠธ์›Œํฌ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/189
| 56์ฐจ์‹œ | 2023.05.18 | BFS | <a href="https://www.acmicpc.net/problem/17836">๊ณต์ฃผ๋‹˜์„ ๊ตฌํ•ด๋ผ!</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/193
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from heapq import *
import sys

def input(): return sys.stdin.readline().rstrip()

N, M, T = map(int, input().split())
board = []

for _ in range(N):
board.append(input().split())

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]
heap = [(0, 0, 0)]
answer = int(1e9)
visited = {(0,0),}
while heap:
now_time, now_row, now_col = heappop(heap)

if now_row == N-1 and now_col == M-1:
answer = min(answer, now_time)
break

if now_time >= T: continue

for dir in range(4):
new_row = now_row + dy[dir]
new_col = now_col + dx[dir]

if new_row < 0 or new_row >= N: continue
if new_col < 0 or new_col >= M: continue
if (new_row, new_col) in visited: continue

if board[new_row][new_col] == "2":
heappush(heap, (now_time+1, new_row, new_col))
answer = min(answer, (now_time+1+(N-1-new_row)+(M-1-new_col)))

elif board[new_row][new_col] == "0":
heappush(heap, (now_time+1, new_row, new_col))

visited.add((new_row, new_col))

print(answer) if answer <= T else print("Fail")

0 comments on commit 5fe64aa

Please sign in to comment.