Skip to content

Conversation

@YoonYn9915
Copy link
Member

@YoonYn9915 YoonYn9915 commented Aug 2, 2025

🌱WIL

이번 한 주의 소감을 작성해주세요!

  • 점점 알고리즘에 신경을 못 쓰는 느낌..

🚀주간 목표 문제 수: 3개

푼 문제


프로그래머스 #81302. 거리두기: 그래프 / level 2

정리한 링크: (바로가기)

🚩플로우 (선택)

코드를 풀이할 때 적었던 플로우가 있나요?

🚩제출한 코드

from collections import deque

def bfs(places, i, j, k):
    queue = deque()
    queue.append((j, k, 0))  # row, col, dist
    visited = [[False] * 5 for _ in range(5)]
    visited[j][k] = True

    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]

    while queue:
        row, col, dist = queue.popleft()

        if dist != 0 and places[i][row][col] == 'P':
            return 1

        if dist == 2:
            continue

        for d in range(4):
            nr = row + dx[d]
            nc = col + dy[d]

            if 0 <= nr < 5 and 0 <= nc < 5 and not visited[nr][nc]:
                if places[i][nr][nc] != 'X':
                    visited[nr][nc] = True
                    queue.append((nr, nc, dist + 1))

    return 0


def solution(places):
    answer = []

    for i in range(5):  # 5 rooms
        violated = False
        for j in range(5):
            for k in range(5):
                if places[i][j][k] == 'P':
                    if bfs(places, i, j, k):
                        violated = True
                        break
            if violated:
                break
        answer.append(0 if violated else 1)

    return answer

💡TIL

배운 점이 있다면 입력해주세요


백준 #2468. 안전영역: 그래프 / 실버 1

정리한 링크: (바로가기)

🚩플로우 (선택)

코드를 풀이할 때 적었던 플로우가 있나요?

🚩제출한 코드

import sys

input = sys.stdin.readline
from collections import deque

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

for i in range(N):
    for j in range(N):
        if graph[i][j] > high:
            high = graph[i][j]

dx, dy = [0, 0, -1, 1], [-1, 1, 0, 0]
queue = deque()


def bfs(i, j, high):
    queue.append((i, j))
    visited[i][j] = 1

    while queue:
        x, y = queue.popleft()

        for i in range(4):
            nx = dx[i] + x
            ny = dy[i] + y

            if nx < 0 or nx >= N or ny < 0 or ny >= N:
                continue

            if graph[nx][ny] > high and visited[nx][ny] == 0:
                visited[nx][ny] = 1
                queue.append((nx, ny))


result = 0
for k in range(high):
    visited = [[0] * N for _ in range(N)]
    ans = 0

    for i in range(N):
        for j in range(N):
            if graph[i][j] > k and visited[i][j] == 0:
                bfs(i, j, k)
                ans += 1

    if result < ans:
        result = ans

print(result)

💡TIL

배운 점이 있다면 입력해주세요


백준 #1026. 보물: 그리디 / 실버 4

정리한 링크: (바로가기)

🚩플로우 (선택)

코드를 풀이할 때 적었던 플로우가 있나요?

🚩제출한 코드

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
s = 0
for i in range(n):
    b_max = max(b)
    s += a[i] * b_max
    b.remove(b_max)

print(s)

💡TIL

배운 점이 있다면 입력해주세요

Copy link
Collaborator

@Mingguriguri Mingguriguri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이번 주 문제는 DFS/BFS 유형 문제였습니다! 크게 어려움이 있는 문제들은 아니었지만 문제 모두 조건들이 있어 해당 조건에 맞춰 DFS/BFS 코드를 적절히 수정하는 게 관건이었던 것 같아요
한 주간 고생 많으셨습니다!

Comment on lines +19 to +36
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BFS로 풀이하셨군요! 이 문제는 DFS, BFS 모두 풀이 가능해서 어떻게 풀이하셨을지 궁금했습니다!
깔끔하게 잘 풀이하신 것 같습니다 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

하나의 함수에서 하나의 역할만 할 수 있도록 bfs 함수 내에서 bfs 탐색 역할만 하도록 코드를 짜신 점이 잘하신 점인 것 같습니다

@YoonYn9915 YoonYn9915 merged commit 6a8555e into main Aug 11, 2025
@github-actions
Copy link

🔥2025-08 챌린지 진행 상황

👉 그리디

  • YoonYn9915: 1개 ❌

👉 구현

  • YoonYn9915: 0개 ❌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants