Skip to content

Conversation

@YoonYn9915
Copy link
Member

@YoonYn9915 YoonYn9915 commented Jun 21, 2025

🌱WIL

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

  • 이번 한주는 내가 발제자로서 최단경로, 그래프(BFS) 문제를 풀고 과제를 선택했다. 전 주에 민정님이 제공했던 숨바꼭질1, 숨바꼭질 2 문제와 비슷한 유형이여서 쉽게 잘 풀수 있었다. 일단 문제없이 잘 풀긴 했는데, 배웠던 걸 기록하고 정리하여 잊어버리지 않고 다음에도 빨리 맞출수 있도록 노션 페이지 만들어야겠다... (붓캠 시작하고는 피곤해서 잘 못했다...)

🚀주간 목표 문제 수: 3개

푼 문제


백준 #14226. 이모티콘: 그래프 / 골드 4

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

🚩제출한 코드

from collections import deque
import sys

S = int(sys.stdin.readline().strip())

# visited[screen][clipboard]
visited = [[-1] * (S + 1) for _ in range(S + 1)]

queue = deque()
queue.append((1, 0))  # 화면: 1, 클립보드: 0
visited[1][0] = 0

while queue:
    screen, clipboard = queue.popleft()

    # 목표 이모티콘 수에 도달하면 종료
    if screen == S:
        print(visited[screen][clipboard])
        break

    # 1. 복사 (화면 -> 클립보드)
    if visited[screen][screen] == -1:
        visited[screen][screen] = visited[screen][clipboard] + 1
        queue.append((screen, screen))

    # 2. 붙여넣기 (클립보드 -> 화면)
    if clipboard != 0 and screen + clipboard <= S and visited[screen + clipboard][clipboard] == -1:
        visited[screen + clipboard][clipboard] = visited[screen][clipboard] + 1
        queue.append((screen + clipboard, clipboard))

    # 3. 삭제 (화면 -1)
    if screen - 1 >= 0 and visited[screen - 1][clipboard] == -1:
        visited[screen - 1][clipboard] = visited[screen][clipboard] + 1
        queue.append((screen - 1, clipboard))

💡TIL

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


백준 #13549. 숨바꼭질 3: 그래프 / 골드 5

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

🚩제출한 코드

import sys
from collections import deque

inp = sys.stdin.readline

N, K = map(int, inp().strip().split())
# 해당 위치로 도달한 최소 시간 저장
visited = [-1] * (100_000 + 1)
visited[N] = 0

# (위치, 시간) 형식
queue = deque()
queue.append((N, 0))

dx = [2, -1, 1]

min_time = -1

while queue:
    subin_loc, time = queue.popleft()

    # 수빈이가 동생에게 도달한 시간까지만 bfs탐색하고 그 후에 종료
    if min_time != -1 and min_time + 2 == time:
        break

    # 수빈이가 동생에게 도달한 시간체크
    if min_time == -1 and subin_loc == K:
        min_time = visited[subin_loc]

    # 수빈의 위치에서 3가지 이동
    for i in range(3):
        if i == 0:
            new_loc = subin_loc * dx[i]
        else:
            new_loc = subin_loc + dx[i]

        # 새 위치가 범위 안
        if 0 <= new_loc <= 100_000:
            # 새로 방문한 위치가 이전에 와보지 못했다면,
            if visited[new_loc] == -1:
                # 방문 시간 설정해주고 경로 초기화
                if i == 0:
                    visited[new_loc] = visited[subin_loc]
                    queue.append((new_loc, time))
                else:
                    visited[new_loc] = visited[subin_loc] + 1
                    queue.append((new_loc, time + 1))


print(visited[K])

💡TIL

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


백준 #10828. 스택: 구현 / 실버 4

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

🚩제출한 코드

import sys
input = sys.stdin.readline

N = int(input())

stack = []
def query():
    Q = input().split()
    if Q[0] == "push":
        stack.append(int(Q[1]))
    elif Q[0] == "pop":
        if len(stack):
            print(stack.pop())
        else:
            print(-1)
    elif Q[0] == "size":
        print(len(stack))
    elif Q[0] == "empty":
        if len(stack):
            print(0)
        else:
            print(1)
    elif Q[0] == "top":
        if len(stack):
            print(stack[-1])
        else:
            print(-1)

for _ in range(N):
    query()

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

BFS를 깊게 들어가니까 헷갈렸는데 좋은 문제 가져와주셔서 감사해요! 한 주간 고생 많으셨습니다 :D

Comment on lines +21 to +33
Copy link
Collaborator

Choose a reason for hiding this comment

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

저는 for문을 썼는데, 윤상님 보니까 굳이 for문 쓸 필요가 없었네요!

Copy link
Member Author

Choose a reason for hiding this comment

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

3가지이기도 하고 반복문으로 묶을 이유가 없다고 생각했어요

Comment on lines +7 to +8
Copy link
Collaborator

Choose a reason for hiding this comment

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

아래에 if 문에서 범위만 잘 지정하면 visited 배열의 크기도 S+1만큼 생성할 수 있다는 것을 알게 되었어요. 저는 아래 조건들을 처리 못해서 결국 vistied 배열의 크기를 1001로 설정했거든요..ㅜ

Copy link
Member Author

Choose a reason for hiding this comment

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

붙여넣기에서 0부터 S까지인지 확인하는 조건만 달아주면 0부터 S까지 배열을 설정해도 괜찮다고 생각했습니다!

Comment on lines +30 to +47
Copy link
Collaborator

Choose a reason for hiding this comment

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

i값에 따라 순간이동(0초), 걷기(1초)를 구분하신 것 같네요!
추후 확장할 때에는 좋은 코드인 것 같습니다.

Copy link
Collaborator

@zaqquum zaqquum left a comment

Choose a reason for hiding this comment

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

이번 주도 고생하셨습니다!

Comment on lines +31 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.

3가지 이동 방법(2*x , x-1 , x+1) 을 변화량 dx 와 인덱스 i 로 정리한 것이 인상적입니다.
민정님 말씀처럼 코드 확장할 때 용이 할 것 같네요!

Comment on lines +23 to +28
Copy link
Collaborator

Choose a reason for hiding this comment

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

혹시 여기 min_time의 역할은 무엇인가요?

Copy link
Member Author

Choose a reason for hiding this comment

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

사실 이전 숨바꼭질 2문제랑 유사하게 풀어가다가 필요없어서 지웠어야 했는데 놔둔거라서 없어도 되는 변수이긴 해요..

@YoonYn9915 YoonYn9915 merged commit a75930c into main Jun 23, 2025
@github-actions
Copy link

🔥2025-06 챌린지 진행 상황

👉 그래프

  • YoonYn9915: 5개 ✅
  • Mingguriguri: 4개 ❌
  • zaqquum: 5개 ✅

👉 구현

  • YoonYn9915: 2개 ❌
  • Mingguriguri: 1개 ❌
  • zaqquum: 2개 ❌

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.

4 participants