From eb456b3305f49f5efdd8dd92c888f49aafe9762f Mon Sep 17 00:00:00 2001 From: Minjeong Kim <101111603+Mingguriguri@users.noreply.github.com> Date: Mon, 19 May 2025 11:22:06 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[PGS]=20=EB=8B=A4=EB=A6=AC=EB=A5=BC=20?= =?UTF-8?q?=EC=A7=80=EB=82=98=EB=8A=94=20=ED=8A=B8=EB=9F=AD=20(Java)=20/?= =?UTF-8?q?=20Level2=20(Java=20=ED=92=80=EC=9D=B4)=20/=2052=EB=B6=84=20/?= =?UTF-8?q?=20=EC=8B=A4=ED=8C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...12\224\355\212\270\353\237\255(java).java" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "minjeong/Stack, Queue, Priority Queue/2025-05-18-[PGS]-\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255(java).java" diff --git "a/minjeong/Stack, Queue, Priority Queue/2025-05-18-[PGS]-\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255(java).java" "b/minjeong/Stack, Queue, Priority Queue/2025-05-18-[PGS]-\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255(java).java" new file mode 100644 index 0000000..f3e5e9b --- /dev/null +++ "b/minjeong/Stack, Queue, Priority Queue/2025-05-18-[PGS]-\353\213\244\353\246\254\353\245\274\354\247\200\353\202\230\353\212\224\355\212\270\353\237\255(java).java" @@ -0,0 +1,33 @@ +import java.util.*; + +class Solution { + public int solution(int bridge_length, int weight, int[] truck_weights) { + + Queue bridge = new LinkedList<>(); + for (int i = 0; i < bridge_length; i++) { + bridge.offer(0); // 처음에 빈 칸으로 채워둔다. + } + + int time = 0; // 전체 경과 시간 + int current = 0; // 다리 위 현재 무게 합 + int idx = 0; // 다음에 보낼 트럭 인덱스 + + while (idx < truck_weights.length || current > 0) { + time++; + // 1. 다리에서 한 칸 빠져나옴 + int left = bridge.poll(); + current -= left; // 빠져나간 게 0일수도 있고, 트럭일 수도 있음. + + // 2. 다음 트럭을 올릴 수 있으면 올리기, 아니면 빈 칸(0) 올리기 + if (idx < truck_weights.length && current + truck_weights[idx] <= weight) { + bridge.offer(truck_weights[idx]); + current += truck_weights[idx]; + idx++; + } + else { + bridge.offer(0); + } + } + return time; + } +} \ No newline at end of file From fce46b10eda05f1a0f2abc2bf9c56edcaa96dd69 Mon Sep 17 00:00:00 2001 From: Minjeong Kim <101111603+Mingguriguri@users.noreply.github.com> Date: Mon, 19 May 2025 14:32:51 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[PGS]=20=EC=A3=BC=EC=8B=9D=EA=B0=80?= =?UTF-8?q?=EA=B2=A9=20(JAVA)=20/=20Level=202=20/=2055=EB=B6=84=20/=20?= =?UTF-8?q?=ED=9E=8C=ED=8A=B8,=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...13\235\352\260\200\352\262\251(java).java" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "minjeong/Stack, Queue, Priority Queue/2025-05-19-[PGS]-\354\243\274\354\213\235\352\260\200\352\262\251(java).java" diff --git "a/minjeong/Stack, Queue, Priority Queue/2025-05-19-[PGS]-\354\243\274\354\213\235\352\260\200\352\262\251(java).java" "b/minjeong/Stack, Queue, Priority Queue/2025-05-19-[PGS]-\354\243\274\354\213\235\352\260\200\352\262\251(java).java" new file mode 100644 index 0000000..012623e --- /dev/null +++ "b/minjeong/Stack, Queue, Priority Queue/2025-05-19-[PGS]-\354\243\274\354\213\235\352\260\200\352\262\251(java).java" @@ -0,0 +1,52 @@ +/* 내 풀이 */ +import java.util.*; + + +class Solution { + public int[] solution(int[] prices) { + int[] answer = new int[prices.length]; + + for (int i = 0; i < answer.length; i++) { + for (int j = i+1; j < answer.length; j++) { + answer[i] += 1; + if (prices[i] > prices[j] ) { + break; + } + } + } + return answer; + } +} + +/* 스택 풀이 */ +import java.util.Stack; + +public class Solution { + public int[] solution(int[] prices) { + int n = prices.length; + int[] answer = new int[n]; + // 아직 가격이 떨어지지 않은 시점들의 인덱스를 담을 스택 + Stack st = new Stack<>(); + + for (int i = 0; i < n; i++) { + // 지금 가격(prices[i])이 스택 위 시점의 가격보다 낮다면, + // 그 시점의 가격은 i 시점에 떨어진 것이므로 + // answer[idx] = i - idx 로 구간 길이를 확정짓고 pop + while (!st.isEmpty() && prices[st.peek()] > prices[i]) { + int idx = st.pop(); + answer[idx] = i - idx; + } + // 현재 시점 i를 스택에 추가 + st.push(i); + } + + // 마지막까지 가격이 떨어지지 않은 인덱스들은 + // 끝까지(마지막 인덱스 n-1) 버틴 시간이 (n-1) - idx + while (!st.isEmpty()) { + int idx = st.pop(); + answer[idx] = (n - 1) - idx; + } + + return answer; + } +} From ab39bc41a5ad069e7eeed75e765bdf00ed1d4fca Mon Sep 17 00:00:00 2001 From: Minjeong Kim <101111603+Mingguriguri@users.noreply.github.com> Date: Tue, 20 May 2025 15:13:55 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[BOJ]=20#7576.=20=ED=86=A0=EB=A7=88?= =?UTF-8?q?=ED=86=A0=20/=20=EA=B3=A8=EB=93=9C5=20/=2060=EB=B6=84=20/=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...6-\355\206\240\353\247\210\355\206\240.py" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "minjeong/DFSBFS/2025-05-19-[\353\260\261\354\244\200]-#7576-\355\206\240\353\247\210\355\206\240.py" diff --git "a/minjeong/DFSBFS/2025-05-19-[\353\260\261\354\244\200]-#7576-\355\206\240\353\247\210\355\206\240.py" "b/minjeong/DFSBFS/2025-05-19-[\353\260\261\354\244\200]-#7576-\355\206\240\353\247\210\355\206\240.py" new file mode 100644 index 0000000..10915b7 --- /dev/null +++ "b/minjeong/DFSBFS/2025-05-19-[\353\260\261\354\244\200]-#7576-\355\206\240\353\247\210\355\206\240.py" @@ -0,0 +1,49 @@ +import sys +from collections import deque +input = sys.stdin.readline + +# 1. 입력 처리 +M, N = map(int, input().split()) # 가로 칸 수, 세로 칸 수 +box = [list(map(int, input().split())) for _ in range(N)] # 토마토 + +# 2. 초기 설정 +queue = deque([]) # 큐 +directions = [(-1, 0), (0, 1), (1, 0), (0, -1)] # 방향벡터 +day = 0 # 정답이 담길 변수 + +# 3. 큐에 초기 익은 토마토 위치 저장 +for i in range(N): + for j in range(M): + if box[i][j] == 1: + queue.append((i, j)) + +# 4. BFS 탐색 +while queue: + # 처음 토마토 꺼내기 + x, y = queue.popleft() + + # 처음 토마토의 인접한 토마토 찾기 + for dx, dy in directions: + nx, ny = x + dx, y + dy + + # 범위 내에 있고, 토마토가 익지 않은 경우 + if (0 <= nx < N and 0 <= ny < M) and (box[nx][ny] == 0): + # 익히고 1 더해주며 횟수 세기 + # 여기서 나온 제일 큰 값이 정답이 된다. + box[nx][ny] += box[x][y] + 1 # 일수 누적 + queue.append((nx, ny)) + + +# 5. 정답 구하기 +for row in box: + for tomato in row: + # 모두 탐색했지만 토마토가 모두 익지 않았다면 -1 출력 + if tomato == 0: + print(-1) + exit() + + # 다 익혔다면 최댓값이 정답 + day = max(day, max(row)) + +# 6. 정답 출력 +print(day - 1) # 처음에 1로 익은 토마토를 표현했으니 1을 빼준다. \ No newline at end of file From 88c9f7c0c3d1253ed6c9500d68928ee651cdb31d Mon Sep 17 00:00:00 2001 From: Minjeong Kim <101111603+Mingguriguri@users.noreply.github.com> Date: Tue, 20 May 2025 15:14:22 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[BOJ]=20#7568.=20=ED=86=A0=EB=A7=88?= =?UTF-8?q?=ED=86=A0=20(3=EC=B0=A8=EC=9B=90)=20/=20=EA=B3=A8=EB=93=9C5=20/?= =?UTF-8?q?=2030=EB=B6=84=20/=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...355\206\240(3\354\260\250\354\233\220).py" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "minjeong/DFSBFS/2025-05-20-[\353\260\261\354\244\200]-#7569-\355\206\240\353\247\210\355\206\240(3\354\260\250\354\233\220).py" diff --git "a/minjeong/DFSBFS/2025-05-20-[\353\260\261\354\244\200]-#7569-\355\206\240\353\247\210\355\206\240(3\354\260\250\354\233\220).py" "b/minjeong/DFSBFS/2025-05-20-[\353\260\261\354\244\200]-#7569-\355\206\240\353\247\210\355\206\240(3\354\260\250\354\233\220).py" new file mode 100644 index 0000000..b0ab067 --- /dev/null +++ "b/minjeong/DFSBFS/2025-05-20-[\353\260\261\354\244\200]-#7569-\355\206\240\353\247\210\355\206\240(3\354\260\250\354\233\220).py" @@ -0,0 +1,45 @@ +import sys +from collections import deque +input = sys.stdin.readline + +# 1. 입력 처리 +M, N, H = map(int, input().split()) # 가로, 세로, 높이 +box = [[list(map(int, input().split())) for _ in range(N)] for _ in range(H)] + +# 2. 초기 변수 설정 +queue = deque([]) +directions = [(-1, 0, 0), (0, 1, 0), (1, 0, 0), (0, -1, 0), + (0, 0, 1), (0, 0, -1)] # 위-오른쪽-아래-왼쪽-앞-뒤 +day = 0 # 정답으로 반환할 변수 + +# 3. 초기 익은 토마토를 큐에 추가하기 +for i in range(H): + for j in range(N): + for k in range(M): + if box[i][j][k] == 1: + queue.append((i, j, k)) + +# 4. BFS 탐색 +while queue: + z, y, x = queue.popleft() + + for dx, dy, dz in directions: + nx, ny, nz = x + dx, y + dy, z + dz + # 범위 내에 있고 아직 안 익은 토마토라면 + if (0 <= nx < M and 0 <= ny < N and 0 <= nz < H) and (box[nz][ny][nx] == 0): + box[nz][ny][nx] += box[z][y][x] + 1 # 익은 날짜 누적 갱신 + queue.append((nz, ny, nx)) + +# 5. 정답 구하기 +for height in box: + for row in height: + for tomato in row: + # 안 익은 토마토가 남아있는지 여부 확인 + if tomato == 0: + print(-1) + exit() + # 익는데 걸린 최대 일수 추적 + day = max(day, max(row)) + +# 6. 정답 출력 +print(day - 1) \ No newline at end of file