250x250
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
- 오버라이딩
- 스프링컨테이너
- 프록시
- 테스트코드
- DI
- 서블릿
- 티스토리챌린지
- 다익스트라
- 코드트리조별과제
- 인터페이스
- objecterror
- fielderror
- HttpServletResponse
- java
- 싱글톤
- 코드트리
- 백준
- equals()
- @configuration
- 스프링
- 예외와 트랜잭션 커밋
- 프로그래머스
- http 메시지 컨버터
- html form
- 코딩테스트
- 의존관계
- 참조변수
- 추상클래스
- 김영한
- 오블완
Archives
- Today
- Total
minOS
프로그래머스 거리두기 확인하기 본문
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/81302
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
from collections import deque
def bfs(q,graph):
x,y = q.popleft()
for dx,dy in {(1,0),(0,1),(-1,0),(0,-1),(-1,1),(1,-1),(1,1),(-1,-1),(0,2),(0,-2),(-2,0),(2,0)} :
nx = x + dx
ny = y + dy
if 0<=nx < 5 and 0<= ny < 5 and not visited[nx][ny] and graph[nx][ny] == "P" :
q.append((nx,ny))
visited[nx][ny]=1
while q:
nnx,nny = q.popleft()
for kx,ky in {(1,0),(0,1),(-1,0),(0,-1),}:
nkx = nnx+kx
nky = nny+ky
if 0<=nkx < 5 and 0<= nky < 5 and (abs(nx-nnx) + abs(ny-nny)) <2 and not visited[nkx][nky] and graph[nkx][nky]== "O":
q.append((nkx,nky))
visited[nkx][nky] =1
if 0<=nkx < 5 and 0<= nky < 5 and (abs(nx-nnx) + abs(ny-nny)) <2 and not visited[nkx][nky] and graph[nkx][nky]== "P":
visited[nkx][nky] =1
return False
return True
def fun(graph):
global visited
visited = [[0 for _ in range(5)] for _ in range(5)]
flag = True
q = deque()
for i in range(5):
for j in range(5):
if graph[i][j] == "X":
visited[i][j] =1
for i in range(5):
for j in range(5):
if graph[i][j] == "P":
q.append((i,j))
if not bfs(q,graph):
flag = False
break
if not flag:
return 0
return 1
def solution(places):
ans =[]
for i in range(len(places)):
ans.append(fun(places[i]))
return ans
오랜만에 머리를 좀 썼다 ..
728x90
'Problem Solving > 프로그래머스' 카테고리의 다른 글
프로그래머스 단속카메라 (1) | 2025.07.25 |
---|---|
프로그래머스 카펫 (3) | 2025.07.24 |
프로그래머스 야근 지수 (0) | 2025.07.07 |
프로그래머스 가장 많이 받은 선물 (0) | 2025.07.05 |
프로그래머스 점프와 순간 이동 (0) | 2025.07.05 |