Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
aa0aa13
[Silver III] Title: IF문 좀 대신 써줘, Time: 372 ms, Memory: 60672 KB -Baek…
Yjooon Apr 29, 2025
ae35270
[Gold III] Title: 불!, Time: 448 ms, Memory: 51348 KB -BaekjoonHub
Yjooon Apr 30, 2025
ea90266
[Gold IV] Title: 뱀, Time: 76 ms, Memory: 12008 KB -BaekjoonHub
Yjooon Apr 30, 2025
fad3573
[Gold IV] Title: 스카이라인 쉬운거, Time: 136 ms, Memory: 17256 KB -BaekjoonHub
Yjooon May 5, 2025
e3414a1
[Silver I] Title: 쉬운 최단거리, Time: 1724 ms, Memory: 83436 KB -BaekjoonHub
Yjooon May 5, 2025
a91f086
[Gold V] Title: 컨베이어 벨트 위의 로봇, Time: 212 ms, Memory: 13484 KB -Baekjo…
Yjooon May 5, 2025
b7d8cec
[Gold V] Title: 빗물, Time: 72 ms, Memory: 11864 KB -BaekjoonHub
Yjooon May 7, 2025
8f787c8
[Silver I] Title: 어두운 건 무서워, Time: 592 ms, Memory: 82500 KB -BaekjoonHub
Yjooon May 7, 2025
9d813d1
[Gold IV] Title: 부분합, Time: 192 ms, Memory: 23144 KB -BaekjoonHub
Yjooon May 10, 2025
5c4677c
[Gold III] Title: 🎵니가 싫어 싫어 너무 싫어 싫어 오지 마 내게 찝쩍대지마🎵 - 1, Time: 740 ms…
Yjooon May 10, 2025
7b10da6
[Gold V] Title: 문자열 게임 2, Time: 244 ms, Memory: 28952 KB -BaekjoonHub
Yjooon May 10, 2025
2e2b887
[Gold IV] Title: 동작 그만. 밑장 빼기냐?, Time: 204 ms, Memory: 23948 KB -Baek…
Yjooon May 11, 2025
0b5f55d
[Gold V] Title: 개똥벌레, Time: 236 ms, Memory: 32248 KB -BaekjoonHub
Yjooon May 12, 2025
41903ac
[Gold IV] Title: 트리의 지름, Time: 172 ms, Memory: 21248 KB -BaekjoonHub
Yjooon May 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions 백준/Gold/14719. 빗물/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# [Gold V] 빗물 - 14719

[문제 링크](https://www.acmicpc.net/problem/14719)

### 성능 요약

메모리: 11864 KB, 시간: 72 ms

### 분류

구현, 시뮬레이션

### 제출 일자

2025년 5월 7일 20:59:07

### 문제 설명

<p>2차원 세계에 블록이 쌓여있다. 비가 오면 블록 사이에 빗물이 고인다.</p>

<p style="text-align: center;"><img alt="" src="https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/14719/1.png" style="height:79px; width:146px"><img alt="" src="https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/14719/2.png" style="height:79px; width:143px"></p>

<p>비는 충분히 많이 온다. 고이는 빗물의 총량은 얼마일까?</p>

### 입력

<p>첫 번째 줄에는 2차원 세계의 세로 길이 H과 2차원 세계의 가로 길이 W가 주어진다. (1 ≤ H, W ≤ 500)</p>

<p>두 번째 줄에는 블록이 쌓인 높이를 의미하는 0이상 H이하의 정수가 2차원 세계의 맨 왼쪽 위치부터 차례대로 W개 주어진다.</p>

<p>따라서 블록 내부의 빈 공간이 생길 수 없다. 또 2차원 세계의 바닥은 항상 막혀있다고 가정하여도 좋다.</p>

### 출력

<p>2차원 세계에서는 한 칸의 용량은 1이다. 고이는 빗물의 총량을 출력하여라.</p>

<p>빗물이 전혀 고이지 않을 경우 0을 출력하여라.</p>

65 changes: 65 additions & 0 deletions 백준/Gold/14719. 빗물/빗물.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import java.util.*;
import java.io.*;

public class Main {
static Deque<Integer> q;
static int result;

public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int H = Integer.parseInt(st.nextToken());
int W = Integer.parseInt(st.nextToken());

st = new StringTokenizer(br.readLine());

q = new ArrayDeque<>();
result = 0;
for (int i = 0; i < W; i++) {
int curr = Integer.parseInt(st.nextToken());
if (q.isEmpty()) {
q.offer(curr);
continue;
}

if (q.peekFirst() <= curr) {
calc();
q.offer(curr);
continue;
} else {
q.offer(curr);
}
}
lastCalc();

System.out.println(result);
}

static void calc() {
int high = q.poll();
while (!q.isEmpty()) {
int curr = q.poll();
result += high - curr;
}
}

static void lastCalc() {
if (!q.isEmpty())
q.poll();

while (!q.isEmpty()) {
int maxHeight = 0;
for (int i : q) {
maxHeight = Math.max(maxHeight, i);
}
while (true) {
int curr = q.poll();
if (curr == maxHeight) {
break;
}
result += maxHeight - curr;
}
}

}
}
28 changes: 28 additions & 0 deletions 백준/Gold/1806. 부분합/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# [Gold IV] 부분합 - 1806

[문제 링크](https://www.acmicpc.net/problem/1806)

### 성능 요약

메모리: 23144 KB, 시간: 192 ms

### 분류

누적 합, 두 포인터

### 제출 일자

2025년 5월 10일 13:44:35

### 문제 설명

<p>10,000 이하의 자연수로 이루어진 길이 N짜리 수열이 주어진다. 이 수열에서 연속된 수들의 부분합 중에 그 합이 S 이상이 되는 것 중, 가장 짧은 것의 길이를 구하는 프로그램을 작성하시오.</p>

### 입력

<p>첫째 줄에 N (10 ≤ N < 100,000)과 S (0 < S ≤ 100,000,000)가 주어진다. 둘째 줄에는 수열이 주어진다. 수열의 각 원소는 공백으로 구분되어져 있으며, 10,000이하의 자연수이다.</p>

### 출력

<p>첫째 줄에 구하고자 하는 최소의 길이를 출력한다. 만일 그러한 합을 만드는 것이 불가능하다면 0을 출력하면 된다.</p>

35 changes: 35 additions & 0 deletions 백준/Gold/1806. 부분합/부분합.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.util.*;
import java.io.*;

public class Main {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int S = Integer.parseInt(st.nextToken());

int[] arr = new int[N+1];
int[] prefix = new int[N+1];

st = new StringTokenizer(br.readLine());
for(int i = 1; i <= N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
prefix[i] = prefix[i-1] + arr[i];
}

int left = 0;
int right = 1;
int result = Integer.MAX_VALUE;
boolean flag = false;
while(right <= N) {
if (prefix[right] - prefix[left] >= S) {
flag = true;
result = Math.min(result, right - left);
left++;
continue;
}
right++;
}
System.out.println(flag ? result : 0);
}
}
30 changes: 30 additions & 0 deletions 백준/Gold/1863. 스카이라인 쉬운거/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# [Gold IV] 스카이라인 쉬운거 - 1863

[문제 링크](https://www.acmicpc.net/problem/1863)

### 성능 요약

메모리: 17256 KB, 시간: 136 ms

### 분류

자료 구조, 스택

### 제출 일자

2025년 5월 5일 18:01:42

### 문제 설명

<p>도시에서 태양이 질 때에 보이는 건물들의 윤곽을 스카이라인이라고 한다. 스카이라인만을 보고서 도시에 세워진 건물이 몇 채인지 알아 낼 수 있을까? 건물은 모두 직사각형 모양으로 밋밋하게 생겼다고 가정한다.</p>

<p>정확히 건물이 몇 개 있는지 알아내는 것은 대부분의 경우에 불가능하고, 건물이 최소한 몇 채 인지 알아내는 것은 가능해 보인다. 이를 알아내는 프로그램을 작성해 보자.</p>

### 입력

<p>첫째 줄에 n이 주어진다. (1 ≤ n ≤ 50,000) 다음 n개의 줄에는 왼쪽부터 스카이라인을 보아 갈 때 스카이라인의 고도가 바뀌는 지점의 좌표 x와 y가 주어진다. (1 ≤ x ≤ 1,000,000. 0 ≤ y ≤ 500,000) 첫 번째 지점의 x좌표는 항상 1이다.</p>

### 출력

<p>첫 줄에 최소 건물 개수를 출력한다.</p>

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.io.*;
import java.util.*;

public class Main {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int N = Integer.parseInt(br.readLine());

int result = 0;

Deque<Integer> q = new ArrayDeque<>();
q.offer(0); // 기초값 0
for(int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
if (y > q.peekLast()) {
q.offerLast(y);
} else {
while(y < q.peekLast()) {
q.pollLast();
result++;
}
}
if (y != q.peekLast())
q.offerLast(y);
}
while (!q.isEmpty() && q.peekLast() != 0) {
q.pollLast();
result++;
}

System.out.println(result);
}
}
38 changes: 38 additions & 0 deletions 백준/Gold/1967. 트리의 지름/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# [Gold IV] 트리의 지름 - 1967

[문제 링크](https://www.acmicpc.net/problem/1967)

### 성능 요약

메모리: 21248 KB, 시간: 172 ms

### 분류

그래프 이론, 그래프 탐색, 트리, 깊이 우선 탐색, 트리의 지름

### 제출 일자

2025년 5월 13일 20:46:16

### 문제 설명

<p>트리(tree)는 사이클이 없는 무방향 그래프이다. 트리에서는 어떤 두 노드를 선택해도 둘 사이에 경로가 항상 하나만 존재하게 된다. 트리에서 어떤 두 노드를 선택해서 양쪽으로 쫙 당길 때, 가장 길게 늘어나는 경우가 있을 것이다. 이럴 때 트리의 모든 노드들은 이 두 노드를 지름의 끝 점으로 하는 원 안에 들어가게 된다.</p>

<p><img alt="" height="123" src="https://www.acmicpc.net/JudgeOnline/upload/201007/ttrrtrtr.png" width="310"></p>

<p>이런 두 노드 사이의 경로의 길이를 트리의 지름이라고 한다. 정확히 정의하자면 트리에 존재하는 모든 경로들 중에서 가장 긴 것의 길이를 말한다.</p>

<p>입력으로 루트가 있는 트리를 가중치가 있는 간선들로 줄 때, 트리의 지름을 구해서 출력하는 프로그램을 작성하시오. 아래와 같은 트리가 주어진다면 트리의 지름은 45가 된다.</p>

<p><img alt="" height="152" src="https://www.acmicpc.net/JudgeOnline/upload/201007/tttttt.png" width="312"></p>

<p>트리의 노드는 1부터 n까지 번호가 매겨져 있다.</p>

### 입력

<p>파일의 첫 번째 줄은 노드의 개수 n(1 ≤ n ≤ 10,000)이다. 둘째 줄부터 n-1개의 줄에 각 간선에 대한 정보가 들어온다. 간선에 대한 정보는 세 개의 정수로 이루어져 있다. 첫 번째 정수는 간선이 연결하는 두 노드 중 부모 노드의 번호를 나타내고, 두 번째 정수는 자식 노드를, 세 번째 정수는 간선의 가중치를 나타낸다. 간선에 대한 정보는 부모 노드의 번호가 작은 것이 먼저 입력되고, 부모 노드의 번호가 같으면 자식 노드의 번호가 작은 것이 먼저 입력된다. 루트 노드의 번호는 항상 1이라고 가정하며, 간선의 가중치는 100보다 크지 않은 양의 정수이다.</p>

### 출력

<p>첫째 줄에 트리의 지름을 출력한다.</p>

68 changes: 68 additions & 0 deletions 백준/Gold/1967. 트리의 지름/트리의 지름.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import java.io.*;
import java.util.*;

public class Main {
static boolean[] isVisited;
static ArrayList<Edge>[] tree;
static int result;
static int farNode;

static class Edge {
int to;
int weight;

Edge(int to, int weight) {
this.to = to;
this.weight = weight;
}
}

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
if (n == 1) {
System.out.println(0);
return;
}
isVisited = new boolean[n + 1];
tree = new ArrayList[n + 1];

for (int i = 1; i <= n; i++) {
tree[i] = new ArrayList<>();
}

for (int i = 1; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());

tree[a].add(new Edge(b, c));
tree[b].add(new Edge(a, c));
}

Arrays.fill(isVisited, false);
dfs(1, 0);

Arrays.fill(isVisited, false);
result = 0;
dfs(farNode, 0);

System.out.println(result);
}

static void dfs(int node, int cost) {
isVisited[node] = true;

if (cost > result) {
result = cost;
farNode = node;
}

for (Edge e : tree[node]) {
if (!isVisited[e.to]) {
dfs(e.to, cost + e.weight);
}
}
}
}
Loading