Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- Module
- 모델링
- 비트마스킹
- 모듈
- RTLEngineer
- 스타트와링크
- 비트마스크알고리즘
- verilog HDL
- 최적화
- Rtl
- dfs연습문제
- verilog
- 가속컴퓨팅
- boj
- 감시
- verilogHDL
- 가속기시스템
- 15683
- 백준
- 알고리즘
- HW
- HDL
- DFS
- 14889
- testbench
- 코딩테스트
- 비트마스크
- HWEngineer
Archives
- Today
- Total
oohyoo 님의 블로그
[Python] 프로그래머스 - 가장 빠른 거리 본문
[문제]
[풀이]
#입력과 출력을 자유롭게 작성해주세요
from collections import deque
def solution(chizu, sh, sw):
queue = deque([(sh, sw, 0)])
dh = [-1, 0, 1, 0]
dw = [0, 1, 0, -1]
while queue:
x, y, dist = queue.popleft()
if chizu[x][y] == 3:
return dist
for dir in range(4):
cx = x+dh[dir]
cy = y+dw[dir]
if (0<=cx<H and 0<=cy<W and chizu[cx][cy] != 1):
if chizu[cx][cy] == 3:
return dist+1
chizu[cx][cy] = 1
queue.append((cx, cy, dist+1))
return -1
global H, W
H, W = map(int, input().split())
chizu = [[0]*W for _ in range(H)]
sh, sw = map(int, input().split())
eh, ew = map(int, input().split())
chizu[eh-1][ew-1] = 3
print(solution(chizu, sh-1, sw-1))
반응형
'코딩테스트' 카테고리의 다른 글
[Python] 프로그래머스 - 미로 탐험1 (0) | 2025.02.04 |
---|---|
[Python] 프로그래머스 - 미로 탐험2 (0) | 2025.02.03 |
[Python] 프로그래머스 - 외톨이 알파벳 (1) | 2025.02.03 |
[Python] 프로그래머스 Sort 교육자료 (0) | 2025.02.03 |
[Python] 프로그래머스 Set 강의자료 (0) | 2025.02.03 |