Skip to content

Commit

Permalink
Merge branch 'main' into 40-H0ngJu
Browse files Browse the repository at this point in the history
  • Loading branch information
H0ngJu authored Feb 3, 2025
2 parents 79e925f + 79f1ee3 commit 5cff202
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 4 deletions.
6 changes: 4 additions & 2 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
=======
57 changes: 57 additions & 0 deletions H0ngJu/๋ˆ„์ ํ•ฉ/์ปฌ๋Ÿฌ๋ณผ.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@
| 61์ฐจ์‹œ | 2024.06.20 | ํฌ๋ฃจ์Šค์นผ | <a href="https://www.acmicpc.net/problem/1774">์šฐ์ฃผ์‹ ๊ณผ์˜ ๊ต๊ฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/212
| 62์ฐจ์‹œ | 2024.07.01 | DP | <a href="https://www.acmicpc.net/problem/1949">์šฐ์ˆ˜ ๋งˆ์„</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/214
| 63์ฐจ์‹œ | 2024.07.08 | BFS | <a href="https://www.acmicpc.net/problem/3108">๋กœ๊ณ </a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/216
| 62์ฐจ์‹œ | 2024.07.01 | DP | <a href="https://www.acmicpc.net/problem/1949">์šฐ์ˆ˜ ๋งˆ์„</a> | https://github.com/AlgoLeadMe/AlgoLeadMse-1/pull/214
| 63์ฐจ์‹œ | 2024.07.08 | BFS | <a href="https://www.acmicpc.net/problem/3108">๋กœ๊ณ </a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/216
| 64์ฐจ์‹œ | 2024.07.12 | ์ตœ์†Œ ๊ณตํ†ต ์กฐ์ƒ | <a href="https://www.acmicpc.net/problem/11812">K์ง„ ํŠธ๋ฆฌ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/217
| 65์ฐจ์‹œ | 2024.07.19 | ์ตœ์†Œ ๊ณตํ†ต ์กฐ์ƒ | <a href="https://www.acmicpc.net/problem/3584">๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๊ณตํ†ต ์กฐ์ƒ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/220
| 66์ฐจ์‹œ | 2024.07.22 | DP | <a href="https://www.acmicpc.net/problem/2169">๋กœ๋ด‡ ์กฐ์ข…ํ•˜๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/222
Expand All @@ -88,4 +86,6 @@
| 82์ฐจ์‹œ | 2024.11.22 | ํฌ์†Œ ๋ฐฐ์—ด | <a href="https://www.acmicpc.net/problem/17435">ํ•ฉ์„ฑํ•จ์ˆ˜์™€ ์ฟผ๋ฆฌ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/257
| 83์ฐจ์‹œ | 2024.12.01 | ์ˆ˜ํ•™ + ๊ตฌํ˜„ | <a href="https://www.acmicpc.net/problem/1033">์นตํ…Œ์ผ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/259
| 84์ฐจ์‹œ | 2024.12.31 | BFS | <a href="https://www.acmicpc.net/problem/4179">๋ถˆ!</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/261
| 85์ฐจ์‹œ | 2025.01.09 | ๋‹ค์ต์ŠคํŠธ๋ผ + ์ด๋ถ„ ํƒ์ƒ‰ | <a href="https://www.acmicpc.net/problem/1800">์ธํ„ฐ๋„ท ์„ค์น˜</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/264
| 86์ฐจ์‹œ | 2025.01.16 | ์ด๋ถ„ ํƒ์ƒ‰ | <a href="https://www.acmicpc.net/problem/1114">ํ†ต๋‚˜๋ฌด ์ž๋ฅด๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/265
---
Original file line number Diff line number Diff line change
@@ -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<right:
mid = (left + right) // 2

if check(mid):
right = mid
answer = mid
else: left = mid

if answer != int(1e9): print(answer)
else: print(-1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import sys

def input(): return sys.stdin.readline().rstrip()

L, K, C = map(int, input().split())
cut_points = sorted(list(map(int, input().split())))
cut_points = [0] + cut_points + [L]

def check(max_len):
cuts = 0
last_cut = L
for i in range(len(cut_points) - 1, 0, -1):
if cut_points[i] - cut_points[i - 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)

0 comments on commit 5cff202

Please sign in to comment.