From 94734e3ea8149ce52d5bbc120992f0a63b1ba951 Mon Sep 17 00:00:00 2001
From: JSPark <48265129+pknujsp@users.noreply.github.com>
Date: Fri, 8 Mar 2024 00:06:40 +0900
Subject: [PATCH 01/12] 2024-03-08
---
...0\354\231\200 \354\227\264\354\207\240.py" | 50 +++++++++++++++++++
pknujsp/README.md | 3 +-
2 files changed, 52 insertions(+), 1 deletion(-)
create mode 100644 "pknujsp/BRUTE_FORCE/38-\354\236\220\353\254\274\354\207\240\354\231\200 \354\227\264\354\207\240.py"
diff --git "a/pknujsp/BRUTE_FORCE/38-\354\236\220\353\254\274\354\207\240\354\231\200 \354\227\264\354\207\240.py" "b/pknujsp/BRUTE_FORCE/38-\354\236\220\353\254\274\354\207\240\354\231\200 \354\227\264\354\207\240.py"
new file mode 100644
index 00000000..e1cc927a
--- /dev/null
+++ "b/pknujsp/BRUTE_FORCE/38-\354\236\220\353\254\274\354\207\240\354\231\200 \354\227\264\354\207\240.py"
@@ -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
\ No newline at end of file
diff --git a/pknujsp/README.md b/pknujsp/README.md
index 571b70d7..88109a6b 100644
--- a/pknujsp/README.md
+++ b/pknujsp/README.md
@@ -38,4 +38,5 @@
| 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) |
\ No newline at end of file
+| 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) | [#153](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/153) |
\ No newline at end of file
From 37805ad76bbcd71a53121035649801594b03c578 Mon Sep 17 00:00:00 2001
From: JSPark <48265129+pknujsp@users.noreply.github.com>
Date: Fri, 8 Mar 2024 00:33:08 +0900
Subject: [PATCH 02/12] 2024-03-08
---
pknujsp/README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pknujsp/README.md b/pknujsp/README.md
index 88109a6b..6859f496 100644
--- a/pknujsp/README.md
+++ b/pknujsp/README.md
@@ -39,4 +39,4 @@
| 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) |
-| 38차시 | 2024.03.08 | BRUTE_FORCE | [자물쇠와 열쇠](https://school.programmers.co.kr/learn/courses/30/lessons/60059) | [#153](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/153) |
\ No newline at end of file
+| 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) |
\ No newline at end of file
From a69d572d70aaf10c496b6f22d7df50dea546da33 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EC=9D=B4=EB=AC=B8=EB=B9=88?= <3412mb@gmail.com>
Date: Thu, 14 Mar 2024 02:39:59 +0900
Subject: [PATCH 03/12] =?UTF-8?q?2024-03-14=20=EB=AC=BC=EC=95=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Munbin-Lee/README.md | 3 +-
.../39-\353\254\274\354\225\275.py" | 45 +++++++++++++++++++
2 files changed, 47 insertions(+), 1 deletion(-)
create mode 100644 "Munbin-Lee/\353\254\270\354\236\220\354\227\264/39-\353\254\274\354\225\275.py"
diff --git a/Munbin-Lee/README.md b/Munbin-Lee/README.md
index 1be0e769..5221cadf 100644
--- a/Munbin-Lee/README.md
+++ b/Munbin-Lee/README.md
@@ -38,5 +38,6 @@
| 35차시 | 2024.02.18 | 백트래킹 | 단어 마방진 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/140 |
| 36차시 | 2024.02.21 | 문자열 | 회문은 회문아니야!! | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/143 |
| 37차시 | 2024.03.05 | 백트래킹 | 석유 시추 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/150 |
-| 37차시 | 2024.03.08 | 트라이 | 전화번호 목록 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/155 |
+| 38차시 | 2024.03.08 | 트라이 | 전화번호 목록 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/155 |
+| 39차시 | 2024.03.14 | 문자열 | 물약 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/160 |
---
diff --git "a/Munbin-Lee/\353\254\270\354\236\220\354\227\264/39-\353\254\274\354\225\275.py" "b/Munbin-Lee/\353\254\270\354\236\220\354\227\264/39-\353\254\274\354\225\275.py"
new file mode 100644
index 00000000..efcfe576
--- /dev/null
+++ "b/Munbin-Lee/\353\254\270\354\236\220\354\227\264/39-\353\254\274\354\225\275.py"
@@ -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)
From 94e034c6e1029dd58debaf83477c988055afccef Mon Sep 17 00:00:00 2001
From: JSPark <48265129+pknujsp@users.noreply.github.com>
Date: Tue, 19 Mar 2024 16:51:08 +0900
Subject: [PATCH 04/12] 2024-03-19
---
pknujsp/README.md | 3 ++-
...50\355\212\270\353\241\244\353\237\254.py" | 24 +++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
create mode 100644 "pknujsp/\355\201\220/39-\353\224\224\354\212\244\355\201\254 \354\273\250\355\212\270\353\241\244\353\237\254.py"
diff --git a/pknujsp/README.md b/pknujsp/README.md
index 6859f496..a5585860 100644
--- a/pknujsp/README.md
+++ b/pknujsp/README.md
@@ -39,4 +39,5 @@
| 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) |
-| 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) |
\ No newline at end of file
+| 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) |
\ No newline at end of file
diff --git "a/pknujsp/\355\201\220/39-\353\224\224\354\212\244\355\201\254 \354\273\250\355\212\270\353\241\244\353\237\254.py" "b/pknujsp/\355\201\220/39-\353\224\224\354\212\244\355\201\254 \354\273\250\355\212\270\353\241\244\353\237\254.py"
new file mode 100644
index 00000000..0a0b4d8e
--- /dev/null
+++ "b/pknujsp/\355\201\220/39-\353\224\224\354\212\244\355\201\254 \354\273\250\355\212\270\353\241\244\353\237\254.py"
@@ -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
\ No newline at end of file
From e6187a1aa3564a4f7278bd16c459afa361c68cf9 Mon Sep 17 00:00:00 2001
From: tgyuu-An
Date: Wed, 20 Mar 2024 00:32:28 +0900
Subject: [PATCH 05/12] 2024-03-20
---
tgyuuAn/README.md | 1 +
.../AB.py" | 80 +++++++++++++++++++
2 files changed, 81 insertions(+)
create mode 100644 "tgyuuAn/\355\212\270\353\235\274\354\235\264/AB.py"
diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md
index f608a203..e95feed4 100644
--- a/tgyuuAn/README.md
+++ b/tgyuuAn/README.md
@@ -43,4 +43,5 @@
| 39차시 | 2023.02.18 | DP | 앱 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/139
| 40차시 | 2023.02.21 | DP | 입대 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/142
| 41차시 | 2023.03.04 | DP | 자두나무 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/148
+| 46차시 | 2023.03.20 | 트라이 | AB | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/165
---
diff --git "a/tgyuuAn/\355\212\270\353\235\274\354\235\264/AB.py" "b/tgyuuAn/\355\212\270\353\235\274\354\235\264/AB.py"
new file mode 100644
index 00000000..6ae80188
--- /dev/null
+++ "b/tgyuuAn/\355\212\270\353\235\274\354\235\264/AB.py"
@@ -0,0 +1,80 @@
+import sys
+from collections import defaultdict
+
+class Node():
+ def __init__(self, key = None):
+ self.key = key
+ self.count = 0
+ self.children = {}
+
+class Tries():
+ def __init__(self):
+ self.head = Node(None)
+
+ def add(self, element):
+ now = self.head
+
+ for char in element:
+ if char not in now.children:
+ now.children[char] = Node(char)
+
+ now = now.children[char]
+ now.count += 1
+
+ def delete(self, element):
+ now = self.head
+
+ for char in element:
+ child = now.children[char]
+ child.count -= 1
+ if child.count == 0: del now.children[char]
+ now = child
+
+ def find(self, element):
+ now = self.head
+ dic = defaultdict(int)
+
+ string = ""
+ for char in element:
+ if char not in now.children: return dic
+
+ string = string + char
+ now = now.children[char]
+ dic[string] = now.count
+
+ return dic
+
+def input(): return sys.stdin.readline().rstrip()
+
+def query(method, target, element):
+ if method == "add": target.add(element)
+
+ if method == "delete": target.delete(element)
+
+ if method == "find":
+ n = len(element)
+ a_result = A.find(element)
+ b_result = B.find(element[::-1])
+
+ answer = 0
+ for a_len in range(1,n):
+ answer += a_result[element[:a_len]] * b_result[element[:a_len-1:-1]]
+
+ print(answer)
+
+N = int(input())
+A = Tries()
+B = Tries()
+method, target, element = "", "", ""
+
+for _ in range(N):
+ _input = input()
+ if _input[:4] == "find":
+ method,element = _input.split()
+ query(method, A, element)
+
+ else:
+ method, target, element = _input.split()
+
+ if target == "A": query(method, A, element)
+ else: query(method, B, element[::-1])
\ No newline at end of file
From a251e77e56d873678dd88a225df91e23eca0c2a8 Mon Sep 17 00:00:00 2001
From: tgyuu-An
Date: Fri, 22 Mar 2024 21:47:59 +0900
Subject: [PATCH 06/12] 2024-03-22
---
tgyuuAn/README.md | 1 +
...33\354\236\210\353\213\250\353\213\244.py" | 33 +++++++++++++++++++
2 files changed, 34 insertions(+)
create mode 100644 "tgyuuAn/\354\210\230\355\225\231/\353\204\210 \353\264\204\354\227\220\353\212\224 \354\272\241\354\202\254\354\235\264\354\213\240\354\235\264 \353\247\233\354\236\210\353\213\250\353\213\244.py"
diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md
index 5d02ba78..1da8210b 100644
--- a/tgyuuAn/README.md
+++ b/tgyuuAn/README.md
@@ -44,4 +44,5 @@
| 40차시 | 2023.02.21 | DP | 입대 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/142
| 41차시 | 2023.03.04 | DP | 자두나무 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/148
| 42차시 | 2023.03.07 | DFS | 스도쿠 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/152
+| 47차시 | 2023.03.22 | 수학, 분할정복 | 너 봄에는 캡사이신이 맛있단다 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/167
---
diff --git "a/tgyuuAn/\354\210\230\355\225\231/\353\204\210 \353\264\204\354\227\220\353\212\224 \354\272\241\354\202\254\354\235\264\354\213\240\354\235\264 \353\247\233\354\236\210\353\213\250\353\213\244.py" "b/tgyuuAn/\354\210\230\355\225\231/\353\204\210 \353\264\204\354\227\220\353\212\224 \354\272\241\354\202\254\354\235\264\354\213\240\354\235\264 \353\247\233\354\236\210\353\213\250\353\213\244.py"
new file mode 100644
index 00000000..ac903fbb
--- /dev/null
+++ "b/tgyuuAn/\354\210\230\355\225\231/\353\204\210 \353\264\204\354\227\220\353\212\224 \354\272\241\354\202\254\354\235\264\354\213\240\354\235\264 \353\247\233\354\236\210\353\213\250\353\213\244.py"
@@ -0,0 +1,33 @@
+import sys
+
+DIV = 1_000_000_007
+
+def input(): return sys.stdin.readline().rstrip()
+
+def power(n, over):
+ if over == 0: return 1
+ elif over == 1: return n
+ elif over %2 == 0:
+ half = (power(n, over//2) % DIV)
+ return (half * half) % DIV
+ else:
+ half = (power(n, over//2) % DIV)
+ return (half * half * (n % DIV)) % DIV
+
+N = int(input())
+numbers = sorted(list(map(int,input().split())))
+DP = [-1 for _ in range(N)]
+answer = 0
+
+for start_idx in range(N):
+ start_num = numbers[start_idx]
+ end_num = numbers[N-start_idx-1]
+
+ # 만약 캐싱이 되어있지 않을 경우 직접 계산
+ if DP[N-start_idx-1] == -1: DP[N-start_idx-1] = power(2, N-start_idx-1)
+
+ # 한번이라도 계산 했으면 바로 이용
+ answer += ((end_num % DIV) * (DP[N-start_idx-1] % DIV)) % DIV
+ answer -= ((start_num % DIV) * (DP[N-start_idx-1] % DIV)) % DIV
+
+print(answer % DIV)
\ No newline at end of file
From 8c9453e2f30d5e0cb29b17078baf35c85bfd2d3f Mon Sep 17 00:00:00 2001
From: JSPark <48265129+pknujsp@users.noreply.github.com>
Date: Fri, 22 Mar 2024 22:52:49 +0900
Subject: [PATCH 07/12] 2024-03-22
---
pknujsp/README.md | 3 ++-
.../40-\354\204\274\354\204\234.py" | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
create mode 100644 "pknujsp/\352\267\270\353\246\254\353\224\224/40-\354\204\274\354\204\234.py"
diff --git a/pknujsp/README.md b/pknujsp/README.md
index a5585860..39896530 100644
--- a/pknujsp/README.md
+++ b/pknujsp/README.md
@@ -40,4 +40,5 @@
| 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) |
| 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) |
\ No newline at end of file
+| 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) |
\ No newline at end of file
diff --git "a/pknujsp/\352\267\270\353\246\254\353\224\224/40-\354\204\274\354\204\234.py" "b/pknujsp/\352\267\270\353\246\254\353\224\224/40-\354\204\274\354\204\234.py"
new file mode 100644
index 00000000..07494620
--- /dev/null
+++ "b/pknujsp/\352\267\270\353\246\254\353\224\224/40-\354\204\274\354\204\234.py"
@@ -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)
From b13d92fbddf0d15f7293cb17216ae4f0cad2efd3 Mon Sep 17 00:00:00 2001
From: JSPark <48265129+pknujsp@users.noreply.github.com>
Date: Mon, 25 Mar 2024 20:01:27 +0900
Subject: [PATCH 08/12] 2024-03-25
---
pknujsp/README.md | 3 +-
...14\352\263\240\354\212\244\355\214\237.py" | 33 +++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 "pknujsp/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/41-\354\225\214\352\263\240\354\212\244\355\214\237.py"
diff --git a/pknujsp/README.md b/pknujsp/README.md
index 39896530..665f42d8 100644
--- a/pknujsp/README.md
+++ b/pknujsp/README.md
@@ -41,4 +41,5 @@
| 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) |
\ No newline at end of file
+| 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) |
\ No newline at end of file
diff --git "a/pknujsp/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/41-\354\225\214\352\263\240\354\212\244\355\214\237.py" "b/pknujsp/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/41-\354\225\214\352\263\240\354\212\244\355\214\237.py"
new file mode 100644
index 00000000..364af0a3
--- /dev/null
+++ "b/pknujsp/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/41-\354\225\214\352\263\240\354\212\244\355\214\237.py"
@@ -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))
From 268b92090d691e8195b66c872e66aad59f332a85 Mon Sep 17 00:00:00 2001
From: H0ngJu
Date: Mon, 25 Mar 2024 23:55:28 +0900
Subject: [PATCH 09/12] 2024-03-25
---
H0ngJu/README.md | 13 +++++----
... \352\263\204\353\213\250 \354\210\230.py" | 28 +++++++++++++++++++
2 files changed, 35 insertions(+), 6 deletions(-)
create mode 100644 "H0ngJu/\354\211\254\354\232\264 \352\263\204\353\213\250 \354\210\230.py"
diff --git a/H0ngJu/README.md b/H0ngJu/README.md
index 2d0adb09..3515bb28 100644
--- a/H0ngJu/README.md
+++ b/H0ngJu/README.md
@@ -1,11 +1,12 @@
## ✏️ 기록
-| 차시 | 날짜 | 문제유형 | 링크 | 풀이 |
-| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: |
-| 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 |
+| 차시 | 날짜 | 문제유형 | 링크 | 풀이 |
+| :---: | :--------: | :------: | :-----------------------------------------------------------------------------------: | :-------------------------------------------------: |
+| 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 |
| 2차시 | 2024.03.07 | 큐 | [다리를 지나는 트럭](https://school.programmers.co.kr/learn/courses/30/lessons/42583) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/153 |
-| 3차시 | 2024.03.10 | 힙 | [N번째 큰 수](https://www.acmicpc.net/problem/2075) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/156 |
-| 4차시 | 2024.03.13 | 힙 | [문제집](https://www.acmicpc.net/problem/1766) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/158 |
-| 5차시 | 2024.03.16 | 구현 | [요세푸스 문제](https://www.acmicpc.net/problem/1158) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/161 |
+| 3차시 | 2024.03.10 | 힙 | [N번째 큰 수](https://www.acmicpc.net/problem/2075) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/156 |
+| 4차시 | 2024.03.13 | 힙 | [문제집](https://www.acmicpc.net/problem/1766) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/158 |
+| 5차시 | 2024.03.16 | 구현 | [요세푸스 문제](https://www.acmicpc.net/problem/1158) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/161 |
+| 8차시 | 2024.03.16 | DP | [쉬운 계단 수](https://www.acmicpc.net/problem/10844) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/170 |
---
diff --git "a/H0ngJu/\354\211\254\354\232\264 \352\263\204\353\213\250 \354\210\230.py" "b/H0ngJu/\354\211\254\354\232\264 \352\263\204\353\213\250 \354\210\230.py"
new file mode 100644
index 00000000..7c5631a2
--- /dev/null
+++ "b/H0ngJu/\354\211\254\354\232\264 \352\263\204\353\213\250 \354\210\230.py"
@@ -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)
+
From d593d25adf9a3b51f85b061c8d21591fe57f830f Mon Sep 17 00:00:00 2001
From: tgyuu-An
Date: Tue, 26 Mar 2024 11:53:54 +0900
Subject: [PATCH 10/12] 2024-03-25
---
tgyuuAn/README.md | 1 +
.../\352\263\250\353\252\251\352\270\270.py" | 78 +++++++++++++++++++
2 files changed, 79 insertions(+)
create mode 100644 "tgyuuAn/\353\262\250\353\247\214 \355\217\254\353\223\234/\352\263\250\353\252\251\352\270\270.py"
diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md
index 5fd3dcb3..2464bc46 100644
--- a/tgyuuAn/README.md
+++ b/tgyuuAn/README.md
@@ -47,4 +47,5 @@
| 43차시 | 2024.03.10 | 이분 탐색 | 징검다리 건너기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/157
| 44차시 | 2023.03.13 | 트라이 | 개미굴 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/159
| 45차시 | 2023.03.16 | 트라이 | 트라이 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/162
+| 48차시 | 2023.03.25 | 벨만 포드 | 골목길 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/171
---
diff --git "a/tgyuuAn/\353\262\250\353\247\214 \355\217\254\353\223\234/\352\263\250\353\252\251\352\270\270.py" "b/tgyuuAn/\353\262\250\353\247\214 \355\217\254\353\223\234/\352\263\250\353\252\251\352\270\270.py"
new file mode 100644
index 00000000..b879b593
--- /dev/null
+++ "b/tgyuuAn/\353\262\250\353\247\214 \355\217\254\353\223\234/\352\263\250\353\252\251\352\270\270.py"
@@ -0,0 +1,78 @@
+import sys
+from collections import deque
+
+def input(): return sys.stdin.readline().rstrip()
+
+N, M = map(int, input().split())
+edge = [[] for _ in range(N+1)]
+
+# 간선 정보 받음
+for _ in range(M):
+ start, destination, cost = map(int,input().split())
+ edge[start].append([destination, cost])
+
+# 초기 세팅
+board = [-int(1e9) for _ in range(N+1)]
+board[1] = 0
+
+# 최적의 경로를 찾기 위해 역추적 하기 위해서 이전 노드를 기록
+prev_node = [-1 for _ in range(N+1)]
+prev_node[1] = 0
+
+for _ in range(N-1):
+ for start in range(1,N+1):
+ for destination, cost in edge[start]:
+ if board[destination] < board[start] + cost:
+ board[destination] = board[start] + cost
+ prev_node[destination] = start
+
+has_cycle = False
+is_connect_target = False
+for start in range(1,N+1):
+ for destination, cost in edge[start]:
+ # 사이클 발생
+ if board[destination] < board[start] + cost:
+ has_cycle = True
+
+ # 사이클이 발생해도 경로랑 관련이 없을 수도 있으므로,
+ # 사이클이 발생한 지점이 목표 지점과 관련이 있는지 체크크
+ deq = deque([start])
+ visited = {start,}
+ while deq:
+ now = deq.popleft()
+
+ for d, c in edge[now]:
+ if d in visited: continue
+
+ deq.append(d)
+ visited.add(d)
+
+ # 사이클이 있고 목표지점 혹은 시작지점과 붙어있으면 -1
+ if d == 1 or d == N:
+ is_connect_target = True
+ break
+
+ if is_connect_target: break
+ break
+
+# 사이클이 있는데 해당 사이클이 목표와 연결되어 있을 경우
+if has_cycle and is_connect_target: print(-1)
+else:
+ answer = []
+ now = N
+ while now != 1:
+ answer.append(now)
+ now = prev_node[now]
+
+ answer.append(now)
+
+ if now != 1: print(-1)
+ else: print(*answer[::-1])
+
+# 총 간선 = 2만개,
+# 총 노드 = 100개
+# 벨만 포드 = ( 간선 X 노드 -1 ) -> 198만 시간 복잡도 가능.
+
+# 최적의 경로
+# 사이클이 발생해도 갈 수 있을 수 있음.
+# 사이클이 없더라도 도달할 수 없을 수 있음.
\ No newline at end of file
From 4bb0d01188ee117b1a94e02655a0c92c55908ecc Mon Sep 17 00:00:00 2001
From: tgyuu-An
Date: Sat, 30 Mar 2024 01:01:09 +0900
Subject: [PATCH 11/12] 2024-03-29
---
tgyuuAn/DP/KCM Travel.py | 30 ++++++++++++++++++++++++++++++
tgyuuAn/README.md | 1 +
2 files changed, 31 insertions(+)
create mode 100644 tgyuuAn/DP/KCM Travel.py
diff --git a/tgyuuAn/DP/KCM Travel.py b/tgyuuAn/DP/KCM Travel.py
new file mode 100644
index 00000000..4e279062
--- /dev/null
+++ b/tgyuuAn/DP/KCM Travel.py
@@ -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")
\ No newline at end of file
diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md
index 5fd3dcb3..41b0c6c5 100644
--- a/tgyuuAn/README.md
+++ b/tgyuuAn/README.md
@@ -47,4 +47,5 @@
| 43차시 | 2024.03.10 | 이분 탐색 | 징검다리 건너기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/157
| 44차시 | 2023.03.13 | 트라이 | 개미굴 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/159
| 45차시 | 2023.03.16 | 트라이 | 트라이 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/162
+| 49차시 | 2023.03.29 | DP | KCM Travel | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/174
---
From 1c426f4e6bc1fbdb9ee83b8d13372706ab6cec9a Mon Sep 17 00:00:00 2001
From: tgyuu-An
Date: Mon, 1 Apr 2024 10:50:46 +0900
Subject: [PATCH 12/12] 2024-04-01
---
"tgyuuAn/BFS/\354\227\264\354\207\240.py" | 97 +++++++++++++++++++++++
tgyuuAn/README.md | 35 ++++----
2 files changed, 115 insertions(+), 17 deletions(-)
create mode 100644 "tgyuuAn/BFS/\354\227\264\354\207\240.py"
diff --git "a/tgyuuAn/BFS/\354\227\264\354\207\240.py" "b/tgyuuAn/BFS/\354\227\264\354\207\240.py"
new file mode 100644
index 00000000..36494506
--- /dev/null
+++ "b/tgyuuAn/BFS/\354\227\264\354\207\240.py"
@@ -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)
\ No newline at end of file
diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md
index 5fd3dcb3..bf65daa1 100644
--- a/tgyuuAn/README.md
+++ b/tgyuuAn/README.md
@@ -29,22 +29,23 @@
| 25차시 | 2023.12.26 | 구현 | 방의 개수 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/90
| 26차시 | 2023.12.29 | BFS | 백조의 호수 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/95
| 27차시 | 2024.01.01 | BFS | 탈옥 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/96
-| 28차시 | 2023.01.04 | 스택 | 히스토그램에서 가장 큰 직사각형 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/99
-| 29차시 | 2023.01.07 | 그리디 | 소트 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/103
-| 30차시 | 2023.01.10 | BFS | 아이템 줍기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/104
-| 31차시 | 2023.01.13 | DP | 진우의 달 여행 (Large) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/105
-| 32차시 | 2023.01.16 | 그리디 | 멀티탭 스케줄링 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/108
-| 33차시 | 2023.01.19 | 이분 탐색 | 배열에서 이동 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/115
-| 34차시 | 2023.01.22 | 힙 | 가운데를 말해요 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/116
-| 35차시 | 2023.01.25 | 이분 탐색 | 공유기 설치 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/120
-| 36차시 | 2023.02.04 | BFS | 로봇 청소기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/126
-| 37차시 | 2023.02.04 | BFS | 교환 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/131
-| 38차시 | 2023.02.15 | DP | 피보나치 수 3 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/138
-| 39차시 | 2023.02.18 | DP | 앱 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/139
-| 40차시 | 2023.02.21 | DP | 입대 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/142
-| 41차시 | 2023.03.04 | DP | 자두나무 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/148
-| 42차시 | 2023.03.07 | DFS | 스도쿠 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/152
+| 28차시 | 2024.01.04 | 스택 | 히스토그램에서 가장 큰 직사각형 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/99
+| 29차시 | 2024.01.07 | 그리디 | 소트 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/103
+| 30차시 | 2024.01.10 | BFS | 아이템 줍기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/104
+| 31차시 | 2024.01.13 | DP | 진우의 달 여행 (Large) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/105
+| 32차시 | 2024.01.16 | 그리디 | 멀티탭 스케줄링 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/108
+| 33차시 | 2024.01.19 | 이분 탐색 | 배열에서 이동 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/115
+| 34차시 | 2024.01.22 | 힙 | 가운데를 말해요 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/116
+| 35차시 | 2024.01.25 | 이분 탐색 | 공유기 설치 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/120
+| 36차시 | 2024.02.04 | BFS | 로봇 청소기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/126
+| 37차시 | 2024.02.04 | BFS | 교환 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/131
+| 38차시 | 2024.02.15 | DP | 피보나치 수 3 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/138
+| 39차시 | 2024.02.18 | DP | 앱 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/139
+| 40차시 | 2024.02.21 | DP | 입대 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/142
+| 41차시 | 2024.03.04 | DP | 자두나무 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/148
+| 42차시 | 2024.03.07 | DFS | 스도쿠 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/152
| 43차시 | 2024.03.10 | 이분 탐색 | 징검다리 건너기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/157
-| 44차시 | 2023.03.13 | 트라이 | 개미굴 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/159
-| 45차시 | 2023.03.16 | 트라이 | 트라이 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/162
+| 44차시 | 2024.03.13 | 트라이 | 개미굴 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/159
+| 45차시 | 2024.03.16 | 트라이 | 트라이 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/162
+| 50차시 | 2024.04.01 | BFS | 열쇠 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/175
---