Skip to content

Conversation

@YoonYn9915
Copy link
Member

@YoonYn9915 YoonYn9915 commented Jun 1, 2025

🌱WIL

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

  • 이번 한 주 면접 3개가 잡혀있어서 알고리즘 공부 할 시간이 적었다. 과제문제는 풀어야 할 것 같아서 어떻게든 풀었다.

🚀주간 목표 문제 수: 3개

푼 문제


백준 #11559. 뿌요뿌요: 그래프 / 골드 4

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

🚩제출한 코드

from collections import deque
from sys import stdin
input = stdin.readline

EMPTY = '.'
dx = (1, -1, 0, 0)
dy = (0, 0, 1, -1)


def delete_block():
    for x, y in blocks:
        board[x][y] = EMPTY


def update_board():
    for y in range(6):
        for t in range(10, -1, -1):
            for x in range(11, t, -1):
                if board[x][y] == EMPTY and board[t][y] != EMPTY:
                    board[x][y], board[t][y] = board[t][y], EMPTY


def is_in_area(x, y):
    return 0 <= x < 12 and 0 <= y < 6


def bfs(x, y):
    queue = deque([(x, y)])
    visited[x][y] = True
    same_blocks = [(x, y)]
    while queue:
        x, y = queue.popleft()
        for d in range(4):
            nx = x + dx[d]
            ny = y + dy[d]
            if is_in_area(nx, ny) and not visited[nx][ny] and board[x][y] == board[nx][ny]:
                queue.append((nx, ny))
                visited[nx][ny] = True
                same_blocks.append((nx, ny))
    return same_blocks



board = [[*input().rstrip()] for _ in range(12)]
flag = True
res = 0
while flag:
    flag = False
    visited = [[False] * 6 for _ in range(12)]
    for i in range(12):
        for j in range(6):
            if board[i][j] != EMPTY and not visited[i][j]:
                blocks = bfs(i, j)
                if len(blocks) >= 4:
                    flag = True
                    delete_block()
    if flag:
        update_board()
        res += 1
print(res)

💡TIL

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

  • 문자열의 문자를 하나씩 쪼개서 문자 리스트로 만드는 방식에는 크게 두가지가 있다.
    [*input().rstrip()]은 리스트 언팩 방식,
    list(input().rstrip())은 함수 방식.
    * 언팩 연산자는 반복 가능한(iterable) 객체를 풀어서 각각의 원소로 분해해주는 연산자.

@YoonYn9915 YoonYn9915 self-assigned this Jun 1, 2025
@YoonYn9915 YoonYn9915 changed the title YoonYn9915/ 5월 4주차 / 2문제 YoonYn9915/ 5월 4주차 / 1문제 Jun 1, 2025
@YoonYn9915 YoonYn9915 merged commit c6b8e63 into main Jun 1, 2025
@github-actions
Copy link

github-actions bot commented Jun 1, 2025

🔥2025-06 챌린지 진행 상황

👉 그래프

  • 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.

2 participants