Skip to content

Conversation

@YoonYn9915
Copy link
Member

@YoonYn9915 YoonYn9915 commented Jun 7, 2025

🌱WIL

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

  • 발제 문제와 과제 문제 풀면서 이런 유형에 대한 자신감이 생긴것 같다. 한번 익숙해지고 풀이방법이 떠오르니까 과제문제 푸는데는 30분도 안걸렸다. 다른 유형 풀다보면 잊어버릴까봐 걱정이다.

🚀주간 목표 문제 수: 3개

푼 문제


백준 #14698 전생했더니 슬라임 연구자였던 건에 대하여 (Hard): 그리디 / 골드 4

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

🚩제출한 코드

import heapq
import sys

inp = sys.stdin.readline
MOD = 1000000007

test_case = int(inp())

for _ in range(test_case):
    N = int(inp())
    arr = list(map(int, inp().split()))

    if N == 1:
        print(1)
        continue

    hq = []
    for num in arr:
        heapq.heappush(hq, num)

    result = 1
    while len(hq) > 1:
        a = heapq.heappop(hq)
        b = heapq.heappop(hq)
        energy = a * b
        result = (result * energy) % MOD
        heapq.heappush(hq, energy)

    print(result)

💡TIL

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

  • python에서 heap 자료구조 사용법이 생각이 안났다. 리스트를 O(N)으로 heap자료구조로 만들어주는 heapify 메서드 사용할 것!

백준 #1388. 바닥 장식: 그래프/ 실버 4

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

🚩제출한 코드

def dfs(x, y):
    if graph[x][y] == '-':
        graph[x][y] = 1
        for _y in [1, -1]:
            Y = y + _y
            if (Y > 0 and Y < m) and graph[x][Y] == '-':
                dfs(x, Y)
    if graph[x][y] == '|':
        graph[x][y] = 1
        for _x in [1, -1]:
            X = x + _x
            if (X > 0 and X < n) and graph[X][y] == '|':
                dfs(X, y)


n, m = map(int, input().split())
graph = []
for _ in range(n):
    graph.append(list(input()))

count = 0
for i in range(n):
    for j in range(m):
        if graph[i][j] == '-' or graph[i][j] == '|':
            dfs(i, j)
            count += 1

백준 #1715. 카드 정렬하기: 그리디 / 골드 4

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

🚩제출한 코드

import sys
import heapq

inp = sys.stdin.readline

N = int(inp().strip())
arr = []
answer = 0

for _ in range(N):
    arr.append(int(inp().strip()))

heapq.heapify(arr)

while len(arr) > 1:
    min1 = heapq.heappop(arr)
    min2 = heapq.heappop(arr)

    answer += min1 + min2
    heapq.heappush(arr, min1 + min2)

print(answer)

@YoonYn9915 YoonYn9915 self-assigned this Jun 7, 2025
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.

한 주간 고생 많으셨습니다!

Comment on lines +11 to +14
Copy link
Collaborator

Choose a reason for hiding this comment

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

시간복잡도까지 구체적으로 적어놓는 점이 배울 점인 것 같네요!

Comment on lines +42 to +44
Copy link
Collaborator

Choose a reason for hiding this comment

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

저는 이 부분을
heapq.heapify(arr) 이런 식으로 작성했습니다!

Copy link
Member Author

Choose a reason for hiding this comment

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

이 문제 풀 당시에는 heapify가 생각이 안났어요 ㅎㅎ

Copy link
Collaborator

Choose a reason for hiding this comment

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

어차피 heap에 저장되어야 하니까 저장할 떄 MOD로 나누는 게 더 좋겠네요! 저는 마지막에 출력할 때만 나누었거든요..

@YoonYn9915 YoonYn9915 merged commit e5e087c into main Jun 8, 2025
@github-actions
Copy link

github-actions bot commented Jun 8, 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.

3 participants