Skip to content

Commit

Permalink
Merge pull request #63 from AlgoLeadMe/15-wkdghdwns199
Browse files Browse the repository at this point in the history
15-wkdghdwns199
  • Loading branch information
wkdghdwns199 authored Mar 27, 2024
2 parents 392bcc8 + 3367eac commit 18146fb
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 1 deletion.
4 changes: 3 additions & 1 deletion wkdghdwns199/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
| 11μ°¨μ‹œ | 2024.03.03 | μŠ€νƒ, 큐, 덱 | <a href="https://www.acmicpc.net/problem/11866">μš”μ„Έν‘ΈμŠ€ 문제 0</a> | <a href="">2024.03.03</a> |
| 12μ°¨μ‹œ | 2024.03.06 | DP | <a href="https://www.acmicpc.net/problem/1010">닀리 놓기</a> | <a href="">2024.03.06</a> |
| 13μ°¨μ‹œ | 2024.03.09 | DP | <a href="https://www.acmicpc.net/problem/1932">μ •μˆ˜ μ‚Όκ°ν˜•</a> | <a href="">2024.03.09</a> |
| 14μ°¨μ‹œ | 2024.03.13 | 집합과 맡 | <a href="https://www.acmicpc.net/problem/20920">μ˜λ‹¨μ–΄ μ•”κΈ°λŠ” κ΄΄λ‘œμ›Œ</a> | <a href="">2024.03.13</a> |
| 14μ°¨μ‹œ | 2024.03.13 | 집합과 맡 | <a href="https://www.acmicpc.net/problem/20920">μ˜λ‹¨μ–΄ μ•”κΈ°λŠ” κ΄΄λ‘œμ›Œ</a> | <a href="">2024.03.13</a> |
| 15μ°¨μ‹œ | 2024.03.20 | μš°μ„ μˆœμœ„ 큐 | <a href="https://www.acmicpc.net/problem/11286">μ ˆλŒ“κ°’ νž™</a> | <a href="">2024.03.20</a> |

77 changes: 77 additions & 0 deletions wkdghdwns199/리뷰풀이/ACM-11657.py
Original file line number Diff line number Diff line change
@@ -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])
11 changes: 11 additions & 0 deletions wkdghdwns199/리뷰풀이/ACM-11659.py
Original file line number Diff line number Diff line change
@@ -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])
42 changes: 42 additions & 0 deletions wkdghdwns199/리뷰풀이/ACM-14938.py
Original file line number Diff line number Diff line change
@@ -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))
17 changes: 17 additions & 0 deletions wkdghdwns199/리뷰풀이/ACM-2170.py
Original file line number Diff line number Diff line change
@@ -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)
24 changes: 24 additions & 0 deletions wkdghdwns199/μš°μ„ μˆœμœ„_큐/ACM-11286.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 18146fb

Please sign in to comment.