Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions minjeong/BruteForce/2025-07-26-[PGS]-거리두기확인하기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
def solution(places):
def is_safe(place):
for i in range(5):
for j in range(5):
if place[i][j] != 'P':
continue

for dx, dy in dirs:
ni, nj = i + dx, j + dy
if not (0 <= ni < 5 and 0 <= nj < 5):
continue
if place[ni][nj] != 'P':
continue

dist = abs(dx) + abs(dy)
if dist == 1:
return 0 # 거리 1에서 바로 P면 위반
elif dist == 2:
# 파티션 여부 확인
if dx == 0: # 수평
if place[i][j + dy // 2] != 'X':
return 0
elif dy == 0: # 수직
if place[i + dx // 2][j] != 'X':
return 0
else: # 대각선
if place[i][nj] != 'X' or place[ni][j] != 'X':
return 0
return 1

dirs = [
(-1, 0), (1, 0), (0, -1), (0, 1), # 거리 1
(-2, 0), (2, 0), (0, -2), (0, 2), # 일직선 거리 2
(-1, -1), (-1, 1), (1, -1), (1, 1) # 대각선 거리 2
]

answer = []
for place in places:
answer.append(is_safe(place))

return answer
41 changes: 41 additions & 0 deletions minjeong/DFSBFS/2025-07-26-[PGS]-거리두기확인하기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
def solution(places):
def is_safe(place):
for i in range(5):
for j in range(5):
if place[i][j] != 'P':
continue

for dx, dy in dirs:
ni, nj = i + dx, j + dy
if not (0 <= ni < 5 and 0 <= nj < 5):
continue
if place[ni][nj] != 'P':
continue

dist = abs(dx) + abs(dy)
if dist == 1:
return 0 # 거리 1에서 바로 P면 위반
elif dist == 2:
# 파티션 여부 확인
if dx == 0: # 수평
if place[i][j + dy // 2] != 'X':
return 0
elif dy == 0: # 수직
if place[i + dx // 2][j] != 'X':
return 0
else: # 대각선
if place[i][nj] != 'X' or place[ni][j] != 'X':
return 0
return 1

dirs = [
(-1, 0), (1, 0), (0, -1), (0, 1), # 거리 1
(-2, 0), (2, 0), (0, -2), (0, 2), # 일직선 거리 2
(-1, -1), (-1, 1), (1, -1), (1, 1) # 대각선 거리 2
]

answer = []
for place in places:
answer.append(is_safe(place))

return answer
42 changes: 42 additions & 0 deletions minjeong/DFSBFS/2025-08-03-[백준]-#2458-안전구역.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sys
sys.setrecursionlimit(100000)

input = sys.stdin.readline

# 방향벡터
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]

def dfs(x, y):
# 깊이 탐색을 하며 안전 영역 탐색
visited[x][y] = True
for dx, dy in directions:
nx, ny = x + dx, y + dy
if 0 <= nx < N and 0 <= ny < N and \
not visited[nx][ny] and map[nx][ny] > h:
dfs(nx, ny)


N = int(input())
map = [list(map(int, input().split())) for _ in range(N)]
max_height = 0

# 맵 내의 최대값 구하기
for m in map:
max_height = max(max_height, max(m))

answer = 0

for h in range(0, max_height + 1): # 물이 잠기지 않는 상황을 고려하여 0부터 시작
visited = [[False for _ in range(N)] for _ in range(N)]
count = 0

for i in range(N):
for j in range(N):
# 아직 방문하지 않았고 h(높이) 이상인 지점이라면 DFS 탐색을 한다.
if not visited[i][j] and map[i][j] > h:
dfs(i, j)
count += 1 # DFS 탐색을 마치면 하나의 안전 영역이므로 count

answer = max(answer, count) # 안전영역 최대 개수 계산

print(answer)