diff --git a/H0ngJu/README.md b/H0ngJu/README.md index 9c61b63..57ae2b1 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -38,6 +38,8 @@ | 34차시 | 2024.11.19 | 누적합 | [개똥벌레](https://www.acmicpc.net/problem/3020) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/256 | | 35차시 | 2024.11.23 | DP | [전깃줄](https://www.acmicpc.net/problem/2565) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/258 | | 36차시 | 2024.12.02 | 수학 | [머리 톡톡](https://www.acmicpc.net/problem/1241) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/260 | -| 36차시 | 2024.12.31 | 그리디 | [회의실 배정](https://www.acmicpc.net/problem/1931) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/261 | - +| 37차시 | 2024.12.31 | 그리디 | [회의실 배정](https://www.acmicpc.net/problem/1931) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/262 | +| 38차시 | 2024.01.06 | 정렬 | [최소 회의실 개수](https://www.acmicpc.net/problem/19598) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/263 | +| 39차시 | 2024.01.18 | 정렬 | [컬러볼](https://www.acmicpc.net/problem/10800) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/266 | | 40차시 | 2025.01.28 | 그리디 | [흙길 보수하기](https://www.acmicpc.net/problem/1911) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/267 | +======= diff --git "a/H0ngJu/\353\210\204\354\240\201\355\225\251/\354\273\254\353\237\254\353\263\274.py" "b/H0ngJu/\353\210\204\354\240\201\355\225\251/\354\273\254\353\237\254\353\263\274.py" new file mode 100644 index 0000000..bf97ff4 --- /dev/null +++ "b/H0ngJu/\353\210\204\354\240\201\355\225\251/\354\273\254\353\237\254\353\263\274.py" @@ -0,0 +1,57 @@ +import sys + +def input(): return sys.stdin.readline().rstrip() + +N = int(input()) +info = [list(map(int, input().split())) + [i] for i in range(N)] +dp = [0 for _ in range(N)] +answer = [0 for _ in range(N)] + +# 완탐 -> 시간 초과 +# a가 b보다 크면 (색이 다르다는 가정 하에), a는 b 값을 + 하면 됨 -> 누적합 -> 전체 값에서 같은 색만 빼주기 + +info.sort(key=lambda x: (x[1], x[0])) +total = 0 +color_sum = [0 for _ in range(200001)] +size_sum = [0 for _ in range(200001)] +pre_size = 0 # 다른 컬러이면서 같은 사이즈인 경우를 위해 저장 +pre_color = 0 + +for i in range(N): + color, size, index = info[i] + + if pre_color == color and pre_size == size: + dp[index] = dp[info[i-1][2]] + else : + dp[index] = total - color_sum[color] - size_sum[size] + + total += size + color_sum[color] += size # 같은 색깔의 합 + size_sum[size] += size # 같은 사이즈의 합 + + pre_size = size + pre_color = color + +for i in dp: + print(i) + +# 예외 케이스 +# 3 +# 1 4 +# 2 4 +# 1 4 + +# 6 +# 1 5 +# 2 6 +# 7 6 +# 5 6 +# 2 6 +# 1 6 + +# 5 +# 3 15 +# 3 15 +# 3 5 +# 1 15 +# 2 10 \ No newline at end of file diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index db250b7..ad6f690 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -65,8 +65,6 @@ | 61차시 | 2024.06.20 | 크루스칼 | 우주신과의 교감 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/212 | 62차시 | 2024.07.01 | DP | 우수 마을 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/214 | 63차시 | 2024.07.08 | BFS | 로고 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/216 -| 62차시 | 2024.07.01 | DP | 우수 마을 | https://github.com/AlgoLeadMe/AlgoLeadMse-1/pull/214 -| 63차시 | 2024.07.08 | BFS | 로고 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/216 | 64차시 | 2024.07.12 | 최소 공통 조상 | K진 트리 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/217 | 65차시 | 2024.07.19 | 최소 공통 조상 | 가장 가까운 공통 조상 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/220 | 66차시 | 2024.07.22 | DP | 로봇 조종하기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/222 @@ -88,4 +86,6 @@ | 82차시 | 2024.11.22 | 희소 배열 | 합성함수와 쿼리 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/257 | 83차시 | 2024.12.01 | 수학 + 구현 | 칵테일 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/259 | 84차시 | 2024.12.31 | BFS | 불! | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/261 +| 85차시 | 2025.01.09 | 다익스트라 + 이분 탐색 | 인터넷 설치 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/264 +| 86차시 | 2025.01.16 | 이분 탐색 | 통나무 자르기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/265 --- diff --git "a/tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\235\270\355\204\260\353\204\267 \354\204\244\354\271\230.py" "b/tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\235\270\355\204\260\353\204\267 \354\204\244\354\271\230.py" new file mode 100644 index 0000000..5773bb3 --- /dev/null +++ "b/tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\354\235\270\355\204\260\353\204\267 \354\204\244\354\271\230.py" @@ -0,0 +1,66 @@ +import sys +from heapq import * + +def input(): return sys.stdin.readline().rstrip() + +N, P, K = map(int, input().split()) +graph = [[int(1e9) for _ in range(N+1)] for _ in range(N+1)] + +for _ in range(P): + start, destination, cost = map(int, input().split()) + graph[start][destination] = min(graph[start][destination], cost) + graph[destination][start] = min(graph[destination][start], cost) + +def check(mid): + if dijkstra(mid): return True + return False + +def dijkstra(_max): + visited = set() + DP = [[int(1e9) for _ in range(K+1)] for _ in range(N+1)] + DP[1][K] = 0 + + # 간선 코스트, 남은 기회, 현재 노드 + heap = [(0, K, 1)] + while heap: + now_cost, now_remain, now_node = heappop(heap) + + if (now_node, now_remain) in visited: continue + visited.add((now_node, now_remain)) + + if DP[now_node][now_remain] < now_cost: continue + DP[now_node][now_remain] = now_cost + + if now_node == N: + return True + + for idx, cost in enumerate(graph[now_node]): + if idx == 0: continue + if cost == int(1e9): continue + + if cost <= _max: + if (idx, now_remain) in visited: continue + if DP[idx][now_remain] > cost: heappush(heap, (cost, now_remain, idx)) + + elif cost > _max and now_remain >= 1: + if (idx, now_remain-1) in visited: continue + if DP[idx][now_remain-1] > cost: heappush(heap, (cost, now_remain-1, idx)) + + for idx in range(1, K+1): + if DP[N][idx] != int(1e9): return True + + return False + +answer = int(1e9) +left = -1 +right = 1_000_001 +while left+1 max_len: + return False + if last_cut - cut_points[i - 1] > max_len: + cuts += 1 + last_cut = cut_points[i] + return cuts <= C + +left, right = 1, L +answer = L +while left <= right: + mid = (left + right) // 2 + if check(mid): + answer = mid + right = mid - 1 + else: + left = mid + 1 + +cuts = 0 +last_cut = L +first_cut = None +for i in range(len(cut_points) - 1, 0, -1): + if last_cut - cut_points[i - 1] > answer: + cuts += 1 + last_cut = cut_points[i] + if C == cuts: + first_cut = cut_points[i] + +if first_cut is None: + first_cut = cut_points[1] + +print(answer, first_cut) \ No newline at end of file