From c4a1bc4636be524a6080c665b3a010244aada67d Mon Sep 17 00:00:00 2001 From: JangHongJoon Date: Wed, 20 Mar 2024 21:27:21 +0900 Subject: [PATCH 1/5] README.md update --- wkdghdwns199/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wkdghdwns199/README.md b/wkdghdwns199/README.md index 21e7e87..e618fec 100644 --- a/wkdghdwns199/README.md +++ b/wkdghdwns199/README.md @@ -14,4 +14,5 @@ | 10차시 | 2024.02.29 | 스택, 큐, 덱 | 큐 2 | 2024.02.29 | | 11차시 | 2024.03.03 | 스택, 큐, 덱 | 요세푸스 문제 0 | 2024.03.03 | | 12차시 | 2024.03.06 | DP | 다리 놓기 | 2024.03.06 | -| 13차시 | 2024.03.09 | DP | 정수 삼각형 | 2024.03.09 | \ No newline at end of file +| 13차시 | 2024.03.09 | DP | 정수 삼각형 | 2024.03.09 | +| 13차시 | 2024.03.20 | 우선순위 큐 | 정수 삼각형 | 2024.03.20 | \ No newline at end of file From 05454b900de111aeca874738c9cd42d9537fd961 Mon Sep 17 00:00:00 2001 From: JangHongJoon Date: Wed, 20 Mar 2024 21:27:32 +0900 Subject: [PATCH 2/5] 2024.03.20 solved --- .../ACM-11286.py" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "wkdghdwns199/\354\232\260\354\204\240\354\210\234\354\234\204_\355\201\220/ACM-11286.py" diff --git "a/wkdghdwns199/\354\232\260\354\204\240\354\210\234\354\234\204_\355\201\220/ACM-11286.py" "b/wkdghdwns199/\354\232\260\354\204\240\354\210\234\354\234\204_\355\201\220/ACM-11286.py" new file mode 100644 index 0000000..8fe9372 --- /dev/null +++ "b/wkdghdwns199/\354\232\260\354\204\240\354\210\234\354\234\204_\355\201\220/ACM-11286.py" @@ -0,0 +1,24 @@ +import sys, heapq +input =sys.stdin.readline +min_heap = [] +max_heap = [] +N = int(input()) +for _ in range(N): + number = int(input()) + if (number > 0) : + heapq.heappush(min_heap, number) + elif (number < 0) : + heapq.heappush(max_heap, -number) + else : + if min_heap : + if max_heap : + if min_heap[0] < max_heap[0] : + print(heapq.heappop(min_heap)) + else : + print(-heapq.heappop(max_heap)) + else : + print(heapq.heappop(min_heap)) + elif max_heap : + print(-heapq.heappop(max_heap)) + else : + print(0) \ No newline at end of file From d44fd9fd19a333b12daee01aa43d71077c4b9bd8 Mon Sep 17 00:00:00 2001 From: JangHongJoon Date: Wed, 20 Mar 2024 21:30:23 +0900 Subject: [PATCH 3/5] README.md update --- wkdghdwns199/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wkdghdwns199/README.md b/wkdghdwns199/README.md index e618fec..3a4fd20 100644 --- a/wkdghdwns199/README.md +++ b/wkdghdwns199/README.md @@ -15,4 +15,4 @@ | 11차시 | 2024.03.03 | 스택, 큐, 덱 | 요세푸스 문제 0 | 2024.03.03 | | 12차시 | 2024.03.06 | DP | 다리 놓기 | 2024.03.06 | | 13차시 | 2024.03.09 | DP | 정수 삼각형 | 2024.03.09 | -| 13차시 | 2024.03.20 | 우선순위 큐 | 정수 삼각형 | 2024.03.20 | \ No newline at end of file +| 15차시 | 2024.03.20 | 우선순위 큐 | 절댓값 힙 | 2024.03.20 | \ No newline at end of file From 3fc286da5d7cce424fc043390118d2333bcf5e33 Mon Sep 17 00:00:00 2001 From: JangHongJoon Date: Sat, 23 Mar 2024 13:50:59 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ACM-11657.py" | 77 +++++++++++++++++++ .../ACM-11659.py" | 11 +++ .../ACM-2170.py" | 17 ++++ 3 files changed, 105 insertions(+) create mode 100644 "wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-11657.py" create mode 100644 "wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-11659.py" create mode 100644 "wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-2170.py" diff --git "a/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-11657.py" "b/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-11657.py" new file mode 100644 index 0000000..8c4218c --- /dev/null +++ "b/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-11657.py" @@ -0,0 +1,77 @@ +''' +문제 +N개의 도시가 있다. 그리고 한 도시에서 출발하여 다른 도시에 도착하는 버스가 M개 있다. +각 버스는 A, B, C로 나타낼 수 있는데, A는 시작도시, B는 도착도시, C는 버스를 타고 이동하는데 걸리는 시간이다. +시간 C가 양수가 아닌 경우가 있다. C = 0인 경우는 순간 이동을 하는 경우, C < 0인 경우는 타임머신으로 시간을 되돌아가는 경우이다. + +1번 도시에서 출발해서 나머지 도시로 가는 가장 빠른 시간을 구하는 프로그램을 작성하시오. + +입력 +첫째 줄에 도시의 개수 N (1 ≤ N ≤ 500), 버스 노선의 개수 M (1 ≤ M ≤ 6,000)이 주어진다. +둘째 줄부터 M개의 줄에는 버스 노선의 정보 A, B, C (1 ≤ A, B ≤ N, -10,000 ≤ C ≤ 10,000)가 주어진다. + +출력 +만약 1번 도시에서 출발해 어떤 도시로 가는 과정에서 시간을 무한히 오래 전으로 되돌릴 수 있다면 첫째 줄에 -1을 출력한다. +그렇지 않다면 N-1개 줄에 걸쳐 각 줄에 1번 도시에서 출발해 2번 도시, 3번 도시, ..., N번 도시로 가는 가장 빠른 시간을 순서대로 출력한다. +만약 해당 도시로 가는 경로가 없다면 대신 -1을 출력한다. + +예제 입력 1 +3 4 +1 2 4 +1 3 3 +2 3 -1 +3 1 -2 +예제 출력 1 +4 +3 +예제 입력 2 +3 4 +1 2 4 +1 3 3 +2 3 -4 +3 1 -2 +예제 출력 2 +-1 +예제 입력 3 +3 2 +1 2 4 +1 2 3 +예제 출력 3 +3 +-1 + +''' + +import sys +input = sys.stdin.readline +INF = int(1e9) + +def bellman_ford(start): + dist[start] = 0 + + for i in range(1,n+1): + for j in range(m): + now, next, cost = edges[j][0], edges[j][1], edges[j][2] + if dist[now] != INF and dist[next] > dist[now] + cost: + dist[next] = dist[now] + cost + if i == n : + return True + return False + +n,m = map(int, input().split()) +edges = [] +dist = [INF] * (n+1) + +for _ in range(m): + a,b,c = map(int, input().split()) + edges.append((a,b,c)) + +negative_cycle = bellman_ford(1) +if negative_cycle : + print(-1) +else : + for i in range(2,n+1): + if dist[i] == INF: + print(-1) + else : + print(dist[i]) \ No newline at end of file diff --git "a/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-11659.py" "b/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-11659.py" new file mode 100644 index 0000000..e9af25e --- /dev/null +++ "b/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-11659.py" @@ -0,0 +1,11 @@ +import sys +input = sys.stdin.readline +N,M = map(int, input().split()) +num_list = list(map(int, input().split())) +accumulate_list = [0] * (N+1) +for i in range(N): + accumulate_list[i+1] = accumulate_list[i] + num_list[i] + +for _ in range(M): + start, end = map(int, input().split()) + print(accumulate_list[end] - accumulate_list[start-1]) \ No newline at end of file diff --git "a/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-2170.py" "b/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-2170.py" new file mode 100644 index 0000000..d527e6e --- /dev/null +++ "b/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-2170.py" @@ -0,0 +1,17 @@ +import sys +input = sys.stdin.readline +N = int(input()) +lines = [list(map(int, input().rstrip().split())) for _ in range(N)] +lines.sort() + +length =0 +current_start = lines[0][0] +current_end = lines[0][1] +for start, end in lines[1:]: + if start > current_end : + print(start, current_end) + length += (current_end - current_start) + current_start = start + current_end = max(current_end, end) +length += (current_end - current_start) +print(length) \ No newline at end of file From 158c6a843c99e8540846900fe76a913bb5641c84 Mon Sep 17 00:00:00 2001 From: JangHongJoon Date: Sat, 23 Mar 2024 20:48:28 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ACM-14938.py" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-14938.py" diff --git "a/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-14938.py" "b/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-14938.py" new file mode 100644 index 0000000..1185986 --- /dev/null +++ "b/wkdghdwns199/\353\246\254\353\267\260\355\222\200\354\235\264/ACM-14938.py" @@ -0,0 +1,42 @@ +import sys +from heapq import * +input = sys.stdin.readline + +def dijkstra(graph, start): + length = [float('inf') for _ in graph] + length[start] = 0 + queue = [] + heappush(queue, [length[start], start]) + + while queue: + current_length, current_target = heappop(queue) + + if length[current_target] < current_length : + continue + + for new_target, new_length in graph[current_target] : + len = current_length + new_length + if len < length[new_target]: + length[new_target] = len + heappush(queue, [len, new_target]) + return length + +items = [] +N,M,R = map(int, input().split()) +T = list(map(int, input().split())) +graph = [[] for _ in range(N+1)] + +for _ in range(R): + start, end, weight = map(int, input().split()) + graph[start].append((end, weight)) + graph[end].append((start, weight)) + +for item in range(1, len(graph)) : + result = dijkstra(graph, item) + get = 0 + for i in range(len(result)): + if result[i] <= M : + get += T[i-1] + items.append(get) + +print(max(items))