Skip to content

Commit

Permalink
Merge branch 'main' into 9-H0ngJu
Browse files Browse the repository at this point in the history
  • Loading branch information
MunbinLee authored May 3, 2024
2 parents 05dbfff + 3f65705 commit bc1f839
Show file tree
Hide file tree
Showing 15 changed files with 544 additions and 17 deletions.
1 change: 1 addition & 0 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
| 5์ฐจ์‹œ | 2024.03.16 | ๊ตฌํ˜„ | [์š”์„ธํ‘ธ์Šค ๋ฌธ์ œ](https://www.acmicpc.net/problem/1158) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/161 |
| 6์ฐจ์‹œ | 2024.03.19 | ์Šคํƒ | [์˜คํฐ์ˆ˜](https://www.acmicpc.net/problem/17298) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/164 |
| 7์ฐจ์‹œ | 2024.03.22 | DP | [1,2,3 ๋”ํ•˜๊ธฐ](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/166 |
| 8์ฐจ์‹œ | 2024.03.16 | DP | [์‰ฌ์šด ๊ณ„๋‹จ ์ˆ˜](https://www.acmicpc.net/problem/10844) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/170 |
| 9์ฐจ์‹œ | 2024.03.22 | DP | [RGB๊ฑฐ๋ฆฌ 2](https://www.acmicpc.net/problem/17404) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/172 |

---
28 changes: 28 additions & 0 deletions H0ngJu/์‰ฌ์šด ๊ณ„๋‹จ ์ˆ˜.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys

DIV = 1_000_000_000

N = int(sys.stdin.readline().rstrip())

dp = [[0] * 10 for _ in range(N+1)]
answer = 0

for i in range(1,N+1):
if i == 1:
for k in range(1,10):
dp[i][k] = 1

else:
for num in range(10):
if num == 0:
dp[i][num] = dp[i-1][1]%DIV
elif num == 9:
dp[i][num] = dp[i-1][8]%DIV
else:
dp[i][num] = (dp[i-1][num-1] + dp[i-1][num+1])%DIV

for k in range(10):
answer += dp[N][k]

print(answer%DIV)

3 changes: 2 additions & 1 deletion Munbin-Lee/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
| 35์ฐจ์‹œ | 2024.02.18 | ๋ฐฑํŠธ๋ž˜ํ‚น | <a href="https://www.acmicpc.net/problem/24891">๋‹จ์–ด ๋งˆ๋ฐฉ์ง„</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/140 |
| 36์ฐจ์‹œ | 2024.02.21 | ๋ฌธ์ž์—ด | <a href="https://www.acmicpc.net/problem/15927">ํšŒ๋ฌธ์€ ํšŒ๋ฌธ์•„๋‹ˆ์•ผ!!</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143 |
| 37์ฐจ์‹œ | 2024.03.05 | ๋ฐฑํŠธ๋ž˜ํ‚น | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/250136">์„์œ  ์‹œ์ถ”</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/150 |
| 37์ฐจ์‹œ | 2024.03.08 | ํŠธ๋ผ์ด | <a href="https://www.acmicpc.net/problem/5052">์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/155 |
| 38์ฐจ์‹œ | 2024.03.08 | ํŠธ๋ผ์ด | <a href="https://www.acmicpc.net/problem/5052">์ „ํ™”๋ฒˆํ˜ธ ๋ชฉ๋ก</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/155 |
| 39์ฐจ์‹œ | 2024.03.14 | ๋ฌธ์ž์—ด | <a href="https://www.acmicpc.net/problem/1050">๋ฌผ์•ฝ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/160 |
---
45 changes: 45 additions & 0 deletions Munbin-Lee/๋ฌธ์ž์—ด/39-๋ฌผ์•ฝ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
stdin = open(0)

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

N, M = map(int, input().split())

prices = {}

for _ in range(N):
item, price = input().split()
prices[item] = int(price)

recipes = []

for _ in range(M):
target, formula = input().split('=')
terms = formula.split('+')
recipes.append([target, terms])

def updatePrice(target, terms):
price = 0

for term in terms:
count = int(term[0])
item = term[1:]

if item not in prices:
return

price += count * prices[item]

if target not in prices or prices[target] > price:
prices[target] = price

for _ in range(M):
for recipe in recipes:
updatePrice(recipe[0], recipe[1])

if 'LOVE' not in prices:
print('-1')
exit()

answer = min(prices['LOVE'], 1000000001)
print(answer)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# ์ž๋ฌผ์‡ ์˜ ์ค‘๊ฐ„ ๋ถ€๋ถ„์ด ๋ชจ๋‘ 1์ธ์ง€ ํ™•์ธ
def is_valid(new_lock):
length = len(new_lock) // 3

for r in range(length, length * 2):
for c in range(length, length * 2):
if new_lock[r][c] != 1:
return False

return True

def solution(key, lock):
n = len(lock)
k = len(key)
new_lock = [[0] * (n * 3) for _ in range(n * 3)]

for r in range(n):
for c in range(n):
new_lock[r + n][c + n] = lock[r][c]

for _ in range(4):
rev_key = key[::-1]
key = []
for c in range(k):
row = []
for r in range(k):
row.append(rev_key[r][c])
key.append(row)

"""
์—ด์‡ ๋ฅผ ๋Œ๋ฆฌ๋Š” ๋กœ์ง์€ ํ•œ ์ค„๋กœ๋„ ๊ตฌํ˜„๊ฐ€๋Šฅ ํ•ฉ๋‹ˆ๋‹ค
key = [row for row in zip(*reversed(key))]
"""

for r in range(n * 2):
for c in range(n * 2):
# ์ž๋ฌผ์‡ ์— ์—ด์‡ ๋ฅผ ๋ผ์šด๋‹ค
for i in range(k):
for j in range(k):
new_lock[r + i][c + j] += key[i][j]

# ์ž๋ฌผ์‡ ์— ์—ด์‡ ๊ฐ€ ๋”ฑ ๋“ค์–ด๊ฐ”๋Š”์ง€ ํ™•์ธ
if is_valid(new_lock):
return True

# ์ž๋ฌผ์‡ ์—์„œ ์—ด์‡ ๋ฅผ ๋นผ์„œ ๋ณต๊ตฌ์‹œํ‚จ๋‹ค
for i in range(k):
for j in range(k):
new_lock[r + i][c + j] -= key[i][j]
return False
6 changes: 5 additions & 1 deletion pknujsp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@
| 34์ฐจ์‹œ | 2024.02.12 | BFS | [์ด๋ถ„ ๊ทธ๋ž˜ํ”„](https://www.acmicpc.net/problem/1707) | [#135](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/135) |
| 35์ฐจ์‹œ | 2024.02.18 | ๊ทธ๋ฆฌ๋”” | [์„ ๋ฌผํ• ์ธ](https://www.acmicpc.net/problem/25947) | [#137](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137) |
| 36์ฐจ์‹œ | 2024.02.21 | ์ด์ง„ํƒ์ƒ‰ | [ํœด๊ฒŒ์†Œ ์„ธ์šฐ๊ธฐ](https://www.acmicpc.net/problem/1477) | [#143](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143) |
| 37์ฐจ์‹œ | 2024.03.04 | ๊ตฌํ˜„ | [n+1 ์นด๋“œ๊ฒŒ์ž„](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#149](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/149) |
| 37์ฐจ์‹œ | 2024.03.04 | ๊ตฌํ˜„ | [n+1 ์นด๋“œ๊ฒŒ์ž„](https://school.programmers.co.kr/learn/courses/30/lessons/258707) | [#149](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/149) |
| 38์ฐจ์‹œ | 2024.03.08 | BRUTE_FORCE | [์ž๋ฌผ์‡ ์™€ ์—ด์‡ ](https://school.programmers.co.kr/learn/courses/30/lessons/60059) | [#154](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/154) |
| 39์ฐจ์‹œ | 2024.03.19 | ํ | [๋””์Šคํฌ ์ปจํŠธ๋กค๋Ÿฌ](https://school.programmers.co.kr/learn/courses/30/lessons/42627) | [#163](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/163) |
| 40์ฐจ์‹œ | 2024.03.22 | ๊ทธ๋ฆฌ๋”” | [์„ผ์„œ](https://www.acmicpc.net/problem/2212) | [#168](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/168) |
| 41์ฐจ์‹œ | 2024.03.25 | ๋‹ค์ต์ŠคํŠธ๋ผ | [์•Œ๊ณ ์ŠคํŒŸ](https://www.acmicpc.net/problem/1261) | [#169](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/169) |
18 changes: 18 additions & 0 deletions pknujsp/๊ทธ๋ฆฌ๋””/40-์„ผ์„œ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from sys import *

N = int(stdin.readline())
K = int(stdin.readline())
SENSORS = sorted(set(map(int, stdin.readline().split())))

if K >= N:
print(0)
exit()

distances = [SENSORS[i] - SENSORS[i - 1] for i in range(1, len(SENSORS))]
distances.sort(reverse=True)

result = 0
for i in range(K - 1, len(distances)):
result += distances[i]

print(result)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from heapq import *
from sys import *

C, R = map(int, stdin.readline().split())
arr = [list(map(int, list(stdin.readline().strip()))) for _ in range(R)]

drc = ((1,0),(-1,0),(0,1),(0,-1))
visited = [[False] * C for _ in range(R)]
heap = [(0, 0, 0)]
target_r = R - 1
target_c = C - 1

while heap:
cost, r, c = heappop(heap)

if r == target_r and c == target_c:
print(cost)
break
if visited[r][c]:
continue

visited[r][c] = True

for dr, dc in drc:
nr = r + dr
nc = c + dc

if not 0 <= nr < R or not 0 <= nc < C:
continue
if visited[nr][nc]:
continue

heappush(heap, (cost + arr[nr][nc], nr, nc))
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from heapq import *
from collections import *

def solution(jobs):
jobs = deque(sorted(jobs))
jobs_num = len(jobs)

curr_time = wait_time = 0
heap = []

while heap or jobs:
while jobs and jobs[0][0] <= curr_time:
requested_time, duration = jobs.popleft()
heappush(heap, (duration, requested_time))

if heap:
duration, requested_time = heappop(heap)

curr_time += duration
wait_time += curr_time - requested_time
else:
curr_time += 1

return wait_time // jobs_num
97 changes: 97 additions & 0 deletions tgyuuAn/BFS/์—ด์‡ .py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import sys
from collections import deque, defaultdict

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

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

T = int(input())

for _ in range(T):

H, W = map(int, input().split())
building = [["." for _ in range(W+2)]]
door_info = defaultdict(set)
keys_i_have = set()

for row in range(H):
_input = "."
_input += input()
_input += "."

for col in range(W+2):
if _input[col] not in ("*", ".", "$") and _input[col].isupper():
door_info[_input[col]].add((row+1, col))

building.append(list(_input))

building.append(["." for _ in range(W+2)])

keys_info = input()
if keys_info != "0":
keys_i_have.update(set(keys_info))

answer = 0
visited = set()
locked_doors_to_access = set()

deq = deque([(0, 0)])
while deq:
now_row, now_col = deq.popleft()

for dir in range(4):
new_row = now_row + dy[dir]
new_col = now_col + dx[dir]

if new_row < 0 or new_row >= H+2: continue
if new_col < 0 or new_col >= W+2: continue
if (new_row, new_col) in visited: continue
if building[new_row][new_col] == "*": continue

# print(now_row, now_col,building[new_row][new_col])
# print(locked_doors_to_access)
# print(keys_i_have)
# print()

if building[new_row][new_col] == "$":
answer += 1
visited.add((new_row, new_col))
deq.append((new_row, new_col))
continue

# ๋ฌธ์„ ๋งŒ๋‚ฌ์„ ๊ฒฝ์šฐ, ์ด ๋•Œ ๊นŒ์ง€ ์–ป์€ ์—ด์‡ ๋กœ ์—ด ์ˆ˜ ์žˆ๋Š” ์ง€ ํ™•์ธํ•จ. ์•„๋‹ ๊ฒฝ์šฐ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ ๋ชฉ๋ก์— ์ถ”๊ฐ€
if building[new_row][new_col].isalpha() and building[new_row][new_col].isupper():

# ์—ด์‡ ๋ฅผ ์ด๋ฏธ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒฝ์šฐ
if building[new_row][new_col].lower() in keys_i_have:
building[new_row][new_col] = "."
visited.add((new_row, new_col))
deq.append((new_row, new_col))

# ์—ด์‡ ๊ฐ€ ์—†์–ด์„œ ๋ฌธ์„ ๋ชป ์—ด ๊ฒฝ์šฐ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ ๋ชฉ๋ก์— ์ถ”๊ฐ€
else: locked_doors_to_access.add((new_row, new_col))

continue

# ์—ด์‡ ๋ฅผ ํš๋“ํ–ˆ์„ ๊ฒฝ์šฐ, ์ด ๋•Œ ๊นŒ์ง€ ๋งŒ๋‚œ ๋ฌธ๋“ค ์ค‘์— ์—ด ์ˆ˜ ์žˆ๋Š” ๊ฒƒ๋“ค์„ queue์— ๋„ฃ์Œ
if building[new_row][new_col].isalpha() and building[new_row][new_col].islower():
keys_i_have.add(building[new_row][new_col])
visited.add((new_row, new_col))
deq.append((new_row, new_col))

for can_open_row, can_open_col in door_info[building[new_row][new_col].upper()]:
if (can_open_row, can_open_col) in locked_doors_to_access:
building[can_open_row][can_open_col] = "."
visited.add((can_open_row, can_open_col))
deq.append((can_open_row, can_open_col))
locked_doors_to_access.discard((can_open_row, can_open_col))

continue

# ๋นˆ ๊ณต๊ฐ„์ผ ๊ฒฝ์šฐ, ๊ทธ๋ƒฅ ์ง€๋‚˜๊ฐ
if building[new_row][new_col] == ".":
visited.add((new_row, new_col))
deq.append((new_row, new_col))

print(answer)
30 changes: 30 additions & 0 deletions tgyuuAn/DP/KCM Travel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from collections import defaultdict, deque
import sys

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

T = int(input())
for _ in range(T):
N, M, K = map(int, input().split())

costs = [[int(1e9) for _ in range(M+1)] for _ in range(N+1)]
costs[1][0] = 0

graph = [[] for _ in range(N+1)]
for _ in range(K):
start, destination, cost, duration = map(int,input().split())
graph[start].append((destination, cost, duration))

# print(edges)

for cost in range(M+1):
for city in range(1, N):
if costs[city][cost] == int(1e9): continue

for now_destination, now_cost, now_duration in graph[city]:

if now_cost + cost <= M and costs[now_destination][cost + now_cost] > costs[city][cost] + now_duration:
costs[now_destination][cost + now_cost] = costs[city][cost] + now_duration

result = min(costs[N])
print(result) if result != int(1e9) else print("Poor KCM")
Loading

0 comments on commit bc1f839

Please sign in to comment.