From 6d36a3da0f0d433bddf818a98b43c08e09ae21b7 Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Mon, 4 Mar 2024 18:21:12 +0900 Subject: [PATCH 01/39] 2024-03-04 --- ...20\353\221\220\353\202\230\353\254\264.py" | 37 +++++++++++++++++++ tgyuuAn/README.md | 1 + 2 files changed, 38 insertions(+) create mode 100644 "tgyuuAn/DP/\354\236\220\353\221\220\353\202\230\353\254\264.py" diff --git "a/tgyuuAn/DP/\354\236\220\353\221\220\353\202\230\353\254\264.py" "b/tgyuuAn/DP/\354\236\220\353\221\220\353\202\230\353\254\264.py" new file mode 100644 index 00000000..051a4cde --- /dev/null +++ "b/tgyuuAn/DP/\354\236\220\353\221\220\353\202\230\353\254\264.py" @@ -0,0 +1,37 @@ +import sys + +def input(): return sys.stdin.readline() + +T, W = map(int,input().split()) + +# DP[i][j][k] i초에 [j]위치에 있고 [k]번의 횟수를 이동했을 때 받을 수 있는 자두 수 +DP = [[[0 for _ in range(W+1)] for _ in range(2+1)] for _ in range(T+1)] + +plums = [] +for _ in range(T): + plums.append(int(input())) + +for time, plum in zip(range(1,T+1), plums): + + for k in range(W+1): + if k == 0: + if plum == 1: + DP[time][1][k] = DP[time-1][1][k]+1 + DP[time][2][k] = DP[time-1][2][k] + + else: + DP[time][1][k] = DP[time-1][1][k] + DP[time][2][k] = DP[time-1][2][k]+1 + continue + + if plum == 1: + DP[time][1][k] = max(DP[time-1][1][k],DP[time-1][2][k-1])+1 + DP[time][2][k] = max(DP[time-1][1][k-1],DP[time-1][2][k]) + + else: + DP[time][1][k] = max(DP[time-1][1][k],DP[time-1][2][k-1]) + DP[time][2][k] = max(DP[time-1][1][k-1],DP[time-1][2][k])+1 + + DP[time][2][0] = 0 + +print(max([max(x) for x in DP[-1]])) \ No newline at end of file diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 530f4f4a..f608a203 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -42,4 +42,5 @@ | 38차시 | 2023.02.15 | DP | 피보나치 수 3 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137 | 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 --- From 1adc4bd9681fd9782ddc26498dbd1c2024c5ff4a Mon Sep 17 00:00:00 2001 From: JSPark <48265129+pknujsp@users.noreply.github.com> Date: Mon, 4 Mar 2024 22:12:45 +0900 Subject: [PATCH 02/39] 2024-03-04 --- pknujsp/README.md | 45 ++++++++-------- ...64\353\223\234\352\262\214\354\236\204.py" | 53 +++++++++++++++++++ 2 files changed, 76 insertions(+), 22 deletions(-) create mode 100644 "pknujsp/\352\265\254\355\230\204/37-\354\271\264\353\223\234\352\262\214\354\236\204.py" diff --git a/pknujsp/README.md b/pknujsp/README.md index ab833635..571b70d7 100644 --- a/pknujsp/README.md +++ b/pknujsp/README.md @@ -1,26 +1,26 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -| :----: | :--------: | :-------------: | :-----------------------------------------------------------------------------------------------: | :--------------------------------------------------------: | -| 1차시 | 2023.10.07 | BRUTE_FORCE | [BOJ_1107](https://www.acmicpc.net/problem/1107) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/2) | -| 2차시 | 2023.10.09 | BRUTE_FORCE | [연속 부분 수열 합의 개수](https://school.programmers.co.kr/learn/courses/30/lessons/131701) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/5) | -| 3차시 | 2023.10.11 | SORT | [최솟값 만들기](https://school.programmers.co.kr/learn/courses/30/lessons/12941?language=python3) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/8) | -| 4차시 | 2023.10.13 | SORT | [튜플](https://school.programmers.co.kr/learn/courses/30/lessons/64065) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/9) | -| 5차시 | 2023.10.15 | 구현 | [괄호 변환](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/13) | -| 6차시 | 2023.10.17 | 탐색 | [쿼드압축 후 개수 세기](https://school.programmers.co.kr/learn/courses/30/lessons/68936) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/16) | -| 7차시 | 2023.10.19 | 탐색 | [무인도 여행](https://school.programmers.co.kr/learn/courses/30/lessons/154540) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/20) | -| 8차시 | 2023.10.21 | 탐색 | [거리두기 확인하기](https://school.programmers.co.kr/learn/courses/30/lessons/81302) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/22) | -| 9차시 | 2023.10.23 | 맵 | [스킬 트리](https://school.programmers.co.kr/learn/courses/30/lessons/49993) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/25) | -| 10차시 | 2023.10.25 | 구현 | [수식 최대화](https://school.programmers.co.kr/learn/courses/30/lessons/67257) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/28) | -| 11차시 | 2023.10.27 | 리스트 | [영어 끝말잇기](https://school.programmers.co.kr/learn/courses/30/lessons/12981) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/30) | -| 12차시 | 2023.10.30 | 큐 | [이중우선순위큐](https://school.programmers.co.kr/learn/courses/30/lessons/42628) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/36) | -| 13차시 | 2023.11.01 | DP | [등굣길](https://school.programmers.co.kr/learn/courses/30/lessons/42898) | [#39](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/39) | -| 14차시 | 2023.11.03 | 맵 | [시소 짝꿍](https://school.programmers.co.kr/learn/courses/30/lessons/152996) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/43) | -| 15차시 | 2023.11.05 | 수학 | [예상 대진표](https://school.programmers.co.kr/learn/courses/30/lessons/12985) | [#47](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/47) | -| 16차시 | 2023.11.08 | 수학 | [숫자 변환하기](https://school.programmers.co.kr/learn/courses/30/lessons/154538) | [#51](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/51) | -| 17차시 | 2023.11.10 | 스택 | [짝지어 제거하기](https://school.programmers.co.kr/learn/courses/30/lessons/12973) | [#54](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/54) | -| 18차시 | 2023.11.13 | 구현 | [키패드 누르기](https://school.programmers.co.kr/learn/courses/30/lessons/67256) | [#60](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/60) | -| 19차시 | 2023.11.17 | 구현 | [실패율](https://school.programmers.co.kr/learn/courses/30/lessons/42889) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/64) | +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +| :----: | :--------: | :-------------: | :-----------------------------------------------------------------------------------------------: | :---------------------------------------------------------: | +| 1차시 | 2023.10.07 | BRUTE_FORCE | [BOJ_1107](https://www.acmicpc.net/problem/1107) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/2) | +| 2차시 | 2023.10.09 | BRUTE_FORCE | [연속 부분 수열 합의 개수](https://school.programmers.co.kr/learn/courses/30/lessons/131701) | [#5](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/5) | +| 3차시 | 2023.10.11 | SORT | [최솟값 만들기](https://school.programmers.co.kr/learn/courses/30/lessons/12941?language=python3) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/8) | +| 4차시 | 2023.10.13 | SORT | [튜플](https://school.programmers.co.kr/learn/courses/30/lessons/64065) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/9) | +| 5차시 | 2023.10.15 | 구현 | [괄호 변환](https://school.programmers.co.kr/learn/courses/30/lessons/60058) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/13) | +| 6차시 | 2023.10.17 | 탐색 | [쿼드압축 후 개수 세기](https://school.programmers.co.kr/learn/courses/30/lessons/68936) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/16) | +| 7차시 | 2023.10.19 | 탐색 | [무인도 여행](https://school.programmers.co.kr/learn/courses/30/lessons/154540) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/20) | +| 8차시 | 2023.10.21 | 탐색 | [거리두기 확인하기](https://school.programmers.co.kr/learn/courses/30/lessons/81302) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/22) | +| 9차시 | 2023.10.23 | 맵 | [스킬 트리](https://school.programmers.co.kr/learn/courses/30/lessons/49993) | [#25](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/25) | +| 10차시 | 2023.10.25 | 구현 | [수식 최대화](https://school.programmers.co.kr/learn/courses/30/lessons/67257) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/28) | +| 11차시 | 2023.10.27 | 리스트 | [영어 끝말잇기](https://school.programmers.co.kr/learn/courses/30/lessons/12981) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/30) | +| 12차시 | 2023.10.30 | 큐 | [이중우선순위큐](https://school.programmers.co.kr/learn/courses/30/lessons/42628) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/36) | +| 13차시 | 2023.11.01 | DP | [등굣길](https://school.programmers.co.kr/learn/courses/30/lessons/42898) | [#39](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/39) | +| 14차시 | 2023.11.03 | 맵 | [시소 짝꿍](https://school.programmers.co.kr/learn/courses/30/lessons/152996) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/43) | +| 15차시 | 2023.11.05 | 수학 | [예상 대진표](https://school.programmers.co.kr/learn/courses/30/lessons/12985) | [#47](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/47) | +| 16차시 | 2023.11.08 | 수학 | [숫자 변환하기](https://school.programmers.co.kr/learn/courses/30/lessons/154538) | [#51](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/51) | +| 17차시 | 2023.11.10 | 스택 | [짝지어 제거하기](https://school.programmers.co.kr/learn/courses/30/lessons/12973) | [#54](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/54) | +| 18차시 | 2023.11.13 | 구현 | [키패드 누르기](https://school.programmers.co.kr/learn/courses/30/lessons/67256) | [#60](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/60) | +| 19차시 | 2023.11.17 | 구현 | [실패율](https://school.programmers.co.kr/learn/courses/30/lessons/42889) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/64) | | 20차시 | 2023.11.20 | 문자열 | [옹알이 (2)](https://school.programmers.co.kr/learn/courses/30/lessons/133499) | [#70](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/70) | | 21차시 | 2023.11.23 | 맵 | [의상](https://school.programmers.co.kr/learn/courses/30/lessons/42578) | [#73](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/73) | | 22차시 | 2023.11.26 | 그리디 | [구명보트](https://school.programmers.co.kr/learn/courses/30/lessons/42885) | [#79](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/79) | @@ -37,4 +37,5 @@ | 33차시 | 2024.02.06 | 큐 | [철로](https://www.acmicpc.net/problem/13334) | [#132](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/132) | | 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) | \ No newline at end of file +| 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 diff --git "a/pknujsp/\352\265\254\355\230\204/37-\354\271\264\353\223\234\352\262\214\354\236\204.py" "b/pknujsp/\352\265\254\355\230\204/37-\354\271\264\353\223\234\352\262\214\354\236\204.py" new file mode 100644 index 00000000..6f1f8396 --- /dev/null +++ "b/pknujsp/\352\265\254\355\230\204/37-\354\271\264\353\223\234\352\262\214\354\236\204.py" @@ -0,0 +1,53 @@ +def solution(coin, cards): + a = set(cards[:len(cards) // 3]) + b = set() + t = len(cards) + 1 + r = 1 + + for i in range(len(cards) // 3 + 1, len(cards), 2): + c1, c2 = cards[i - 1], cards[i] + b.add(c1) + b.add(c2) + + removed = False + # 현재 가지고 있는 카드 목록 중 n + 1이 가능한 경우 확인 + for x in list(a): + if t - x in a: + a.remove(t - x) + a.remove(x) + removed = True + break + + if removed: + r += 1 + continue + + # 코인으로 교환해서 얻을 수 있는 카드 중에서 n + 1이 되는 경우를 찾아야 함 + # 코인이 없으므로 종료 + if not coin: + break + + # `현재 갖고 있는 카드 + 얻을 수 있는 카드` = n + 1이 되는 경우를 확인 + for x in list(b): + if t - x in a: + a.remove(t - x) + b.remove(x) + removed = True + coin -= 1 + break + # 마지막 방법으로, 오직 교환으로 얻을 수 있는 카드 목록 중에서 n + 1이 되는 경우를 확인 + if not removed and coin >= 2: + for x in list(b): + if t - x in b: + b.remove(t - x) + b.remove(x) + removed = True + coin -= 2 + break + + # n + 1을 어떤 경우에도 못 만들면 종료 + if not removed: + break + r += 1 + + return r \ No newline at end of file From 9fda61430e9236c5fdc15766de13b8647cc3de0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EB=AC=B8=EB=B9=88?= <3412mb@gmail.com> Date: Tue, 5 Mar 2024 12:40:20 +0900 Subject: [PATCH 03/39] =?UTF-8?q?2024-03-05=20=EC=84=9D=EC=9C=A0=20?= =?UTF-8?q?=EC=8B=9C=EC=B6=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Munbin-Lee/README.md | 1 + ...\354\234\240 \354\213\234\354\266\224.cpp" | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 "Munbin-Lee/\353\260\261\355\212\270\353\236\230\355\202\271/37-\354\204\235\354\234\240 \354\213\234\354\266\224.cpp" diff --git a/Munbin-Lee/README.md b/Munbin-Lee/README.md index 79bc19ee..13e29ef2 100644 --- a/Munbin-Lee/README.md +++ b/Munbin-Lee/README.md @@ -37,4 +37,5 @@ | 34차시 | 2024.02.06 | 구현 | 피자 굽기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/133 | | 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 | --- diff --git "a/Munbin-Lee/\353\260\261\355\212\270\353\236\230\355\202\271/37-\354\204\235\354\234\240 \354\213\234\354\266\224.cpp" "b/Munbin-Lee/\353\260\261\355\212\270\353\236\230\355\202\271/37-\354\204\235\354\234\240 \354\213\234\354\266\224.cpp" new file mode 100644 index 00000000..b2acdd8a --- /dev/null +++ "b/Munbin-Lee/\353\260\261\355\212\270\353\236\230\355\202\271/37-\354\204\235\354\234\240 \354\213\234\354\266\224.cpp" @@ -0,0 +1,78 @@ +#include +#include +#include +#include + +using namespace std; + +int solution(vector> land) { + int r = land.size(); + int c = land[0].size(); + + int dy[4] {-1, 0, 1, 0}; + int dx[4] {0, -1, 0, 1}; + + vector> chunks(r, vector (c, -1)); + vector oils; + + auto bfs = [&](int y, int x, int chunk) { + queue> q; + q.emplace(y, x); + + int oil = 0; + + while (!q.empty()) { + auto [cy, cx] = q.front(); + q.pop(); + + oil++; + chunks[cy][cx] = chunk; + + for (int dir = 0; dir < 4; dir++) { + int ny = cy + dy[dir]; + int nx = cx + dx[dir]; + + if (ny == -1 || ny == r || nx == -1 || nx == c) continue; + if (land[ny][nx] == 0) continue; + + land[ny][nx] = 0; + q.emplace(ny, nx); + } + } + + oils.emplace_back(oil); + }; + + for (int y = 0; y < r; y++) { + for (int x = 0; x < c; x++) { + if (land[y][x] == 0) continue; + + land[y][x] = 0; + bfs(y, x, oils.size()); + } + } + + int answer = -1; + + for (int x = 0; x < c; x++) { + unordered_set set; + + for (int y = 0; y < r; y++) { + int chunk = chunks[y][x]; + + if (chunk == -1) continue; + + set.emplace(chunk); + } + + int oil = 0; + + for (int chunk : set) { + oil += oils[chunk]; + } + + answer = max(answer, oil); + } + + return answer; +} From fedd1ccb20970d0dd56fcfacb55f026893d2c28c Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Tue, 5 Mar 2024 14:01:00 +0900 Subject: [PATCH 04/39] 2024-03-05 --- H0ngJu/README.md | 9 +++++---- "H0ngJu/\355\201\220/process.py" | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 "H0ngJu/\355\201\220/process.py" diff --git a/H0ngJu/README.md b/H0ngJu/README.md index d01c5315..3a8c7669 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -1,6 +1,7 @@ -## ✏️ 기록 +## ✏️ 기록 + +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :--: | +| 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | | -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -|:----:|:---------:|:----:|:-----:|:----:| -| 1차시 | 2024.03.04 | BFS | 리코쳇 로봇 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/1 | --- diff --git "a/H0ngJu/\355\201\220/process.py" "b/H0ngJu/\355\201\220/process.py" new file mode 100644 index 00000000..fd8edd05 --- /dev/null +++ "b/H0ngJu/\355\201\220/process.py" @@ -0,0 +1,18 @@ +from collections import deque + +def solution(priorities, location): + answer = 0 + queue = deque([(i, k) for i, k in enumerate(priorities)]) # 튜플 큐 생성 + priorities.sort(reverse=True) # 내림차순 정렬 + + while queue: + cur = queue.popleft() # 가장 앞의 프로세스 꺼내기 (queue.pop(0)) + if cur[0] == priorities[0]: # 내림차순으로 정렬된 우선순위 == 현재 순위 -> 가장 높음 + answer += 1 # 수 ++ + if cur[1] == location: # 찾고자하는 process인 경우 + break + priorities.pop(0) + else: + queue.append(cur) # 뒤로 미루기 + + return answer \ No newline at end of file From 3c92be6467751a6cd900be87c54b47b940855e44 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Tue, 5 Mar 2024 14:09:04 +0900 Subject: [PATCH 05/39] test --- "H0ngJu/\355\201\220/process.py" | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git "a/H0ngJu/\355\201\220/process.py" "b/H0ngJu/\355\201\220/process.py" index fd8edd05..86bde575 100644 --- "a/H0ngJu/\355\201\220/process.py" +++ "b/H0ngJu/\355\201\220/process.py" @@ -15,4 +15,6 @@ def solution(priorities, location): else: queue.append(cur) # 뒤로 미루기 - return answer \ No newline at end of file + return answer + +#test \ No newline at end of file From c1f3ff726f88fa409153705470ced9114c757a2e Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Tue, 5 Mar 2024 14:51:08 +0900 Subject: [PATCH 06/39] 2024-03-05 --- "H0ngJu/\355\201\220/process.py" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/H0ngJu/\355\201\220/process.py" "b/H0ngJu/\355\201\220/process.py" index 86bde575..b966f0a5 100644 --- "a/H0ngJu/\355\201\220/process.py" +++ "b/H0ngJu/\355\201\220/process.py" @@ -2,7 +2,7 @@ def solution(priorities, location): answer = 0 - queue = deque([(i, k) for i, k in enumerate(priorities)]) # 튜플 큐 생성 + queue = deque([(i, k) for k, i in enumerate(priorities)]) # 튜플 큐 생성 priorities.sort(reverse=True) # 내림차순 정렬 while queue: From 771fb24ea3562502703f56030933b7f4abe3c090 Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Thu, 7 Mar 2024 23:06:02 +0900 Subject: [PATCH 07/39] 2024-03-07 --- .../\354\212\244\353\217\204\354\277\240.py" | 78 +++++++++++++++++++ tgyuuAn/README.md | 1 + 2 files changed, 79 insertions(+) create mode 100644 "tgyuuAn/DFS/\354\212\244\353\217\204\354\277\240.py" diff --git "a/tgyuuAn/DFS/\354\212\244\353\217\204\354\277\240.py" "b/tgyuuAn/DFS/\354\212\244\353\217\204\354\277\240.py" new file mode 100644 index 00000000..7905dc67 --- /dev/null +++ "b/tgyuuAn/DFS/\354\212\244\353\217\204\354\277\240.py" @@ -0,0 +1,78 @@ +import sys + +def input(): return sys.stdin.readline().rstrip() + +board = [] + +for _ in range(9): board.append(list(input())) + +def dfs(board, now_row, now_col): + + # 이미 들어있는 칸일 경우 + if board[now_row][now_col] != "0": + new_row = now_row + new_col = now_col + 1 + + if new_col >= 9: + new_col = 0 + new_row += 1 + + # 스도쿠 완성 + if new_row >= 9: return board + + temp = dfs(board, new_row, new_col) + + if temp is not None: return temp + + # 비어있는 칸일 경우 + else: + need_number = { str(x) for x in range(1,10) } + + # 가로 행 검사 + for col in range(9): + if board[now_row][col] != "0": + need_number.discard(board[now_row][col]) + + # 세로 행 검사 + for row in range(9): + if board[row][now_col] != "0": + need_number.discard(board[row][now_col]) + + # 3X3 검사 + temp_row = (now_row//3)*3 + temp_col = (now_col//3)*3 + for inner_row in range(temp_row, temp_row+3): + for inner_col in range(temp_col, temp_col+3): + if board[inner_row][inner_col] != "0": + need_number.discard(board[inner_row][inner_col]) + + # 만약 넣을 수 있는것이 없으면 None을 리턴 + if len(need_number) == 0: return None + + need_number = sorted(list(map(int,need_number))) + + for dedicate_number in need_number: + board[now_row][now_col] = str(dedicate_number) + + new_row = now_row + new_col = now_col + 1 + + if new_col >= 9: + new_col = 0 + new_row += 1 + + # 스도쿠 완성 + if new_row >= 9: return board + + temp = dfs(board, new_row, new_col) + + if temp is not None: return temp + + board[now_row][now_col] = "0" + + return None + +answer = dfs(board, 0, 0) + +for row in answer: + print("".join(row)) \ No newline at end of file diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 530f4f4a..ab70aff5 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -42,4 +42,5 @@ | 38차시 | 2023.02.15 | DP | 피보나치 수 3 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137 | 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 +| 42차시 | 2023.03.07 | DFS | 스도쿠 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/152 --- From e06b723427e65c043325943adecfe50f7c30c08d Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Thu, 7 Mar 2024 23:59:59 +0900 Subject: [PATCH 08/39] =?UTF-8?q?readme=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- H0ngJu/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/H0ngJu/README.md b/H0ngJu/README.md index 3a8c7669..af4ff40e 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -1,7 +1,7 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :--: | -| 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | | +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | +| 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | --- From 0a0d51ed566616a36f37f9abd8225122f6832dcc Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Fri, 8 Mar 2024 00:02:55 +0900 Subject: [PATCH 09/39] 2024-03-07 --- H0ngJu/README.md | 7 ++--- ...0\353\212\224 \355\212\270\353\237\255.py" | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 "H0ngJu/\355\201\220/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.py" diff --git a/H0ngJu/README.md b/H0ngJu/README.md index af4ff40e..51325d9c 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -1,7 +1,8 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | -| 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 | --- diff --git "a/H0ngJu/\355\201\220/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.py" "b/H0ngJu/\355\201\220/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.py" new file mode 100644 index 00000000..31404e34 --- /dev/null +++ "b/H0ngJu/\355\201\220/\353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255.py" @@ -0,0 +1,26 @@ +from collections import deque + +def solution(bridge_length, weight, truck_weights): + time = 0 + onBridge = deque() # 현재 다리 위에 있는 트럭 + truckNum = 0 # 현재 다리 위에 있는 트럭 수 + sum = 0 # 현재 다리 위에 있는 트럭 무게의 합 + truck_weights = deque(truck_weights) + + while truck_weights or onBridge: + time += 1 + + # 트럭이 다리를 지나가는 경우 처리 + if onBridge and time - onBridge[0][1] >= bridge_length: + sum -= onBridge.popleft()[0] + truckNum -= 1 + + # 다음 트럭이 다리에 올라갈 수 있는 경우 처리 + # 트럭이 있고 합이 weight을 넘지 않으며, 수가 bridge_length를 넘기지 않는 경우 + if len(truck_weights) != 0 and sum + truck_weights[0] <= weight and truckNum + 1 <= bridge_length: + truck = truck_weights.popleft() # pop + onBridge.append((truck, time)) # 다리 위의 truck에 tuple 추가 + sum += truck # 무게 추가 + truckNum += 1 # 건너고 있는 트럭 추가 + + return time \ No newline at end of file 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 10/39] 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 11/39] 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 a2861d9f5d4e1939f05bd3d90fb862f0fa54116a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EB=AC=B8=EB=B9=88?= <3412mb@gmail.com> Date: Fri, 8 Mar 2024 06:45:33 +0900 Subject: [PATCH 12/39] =?UTF-8?q?2024-03-08=20=EC=A0=84=ED=99=94=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=AA=A9=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Munbin-Lee/README.md | 1 + ...\355\230\270 \353\252\251\353\241\235.cpp" | 80 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 "Munbin-Lee/\355\212\270\353\246\254/38-\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.cpp" diff --git a/Munbin-Lee/README.md b/Munbin-Lee/README.md index 13e29ef2..1be0e769 100644 --- a/Munbin-Lee/README.md +++ b/Munbin-Lee/README.md @@ -38,4 +38,5 @@ | 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 | --- diff --git "a/Munbin-Lee/\355\212\270\353\246\254/38-\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.cpp" "b/Munbin-Lee/\355\212\270\353\246\254/38-\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.cpp" new file mode 100644 index 00000000..5e5033f9 --- /dev/null +++ "b/Munbin-Lee/\355\212\270\353\246\254/38-\354\240\204\355\231\224\353\262\210\355\230\270 \353\252\251\353\241\235.cpp" @@ -0,0 +1,80 @@ +#include +#include + +using namespace std; + +struct Trie { + struct Node { + Node *children[10]{}; + bool isTerminal = false; + }; + + Node *root = new Node; + + bool insert(string &s) const { + auto cur = root; + + for (char ch: s) { + int digit = ch - '0'; + + if (!cur->children[digit]) { + cur->children[digit] = new Node(); + cur = cur->children[digit]; + continue; + } + + if (cur->children[digit]->isTerminal) { + return false; + } + + cur = cur->children[digit]; + } + + for (auto child: cur->children) { + if (child) { + return false; + } + } + + cur->isTerminal = true; + + return true; + } +}; + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + + auto solve = []() { + auto trie = new Trie; + + int n; + cin >> n; + + vector numbers(n); + + for (auto &number: numbers) { + cin >> number; + } + + for (auto number: numbers) { + if (!trie->insert(number)) { + cout << "NO\n"; + delete trie; + return; + } + } + + cout << "YES\n"; + }; + + int t; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} From c9c076be0b870253cfb330a5c1f8cf71e6dba8a5 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Sun, 10 Mar 2024 14:37:44 +0900 Subject: [PATCH 13/39] 2024-03-10 --- H0ngJu/README.md | 1 + ...\354\247\270 \355\201\260 \354\210\230.py" | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 "H0ngJu/\355\236\231/N\353\262\210\354\247\270 \355\201\260 \354\210\230.py" diff --git a/H0ngJu/README.md b/H0ngJu/README.md index af4ff40e..2d4e7722 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -3,5 +3,6 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | | :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | | 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | +| 3차시 | 2024.03.10 | 힙 | [N번째 큰 수](https://www.acmicpc.net/problem/2075) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/156 | --- diff --git "a/H0ngJu/\355\236\231/N\353\262\210\354\247\270 \355\201\260 \354\210\230.py" "b/H0ngJu/\355\236\231/N\353\262\210\354\247\270 \355\201\260 \354\210\230.py" new file mode 100644 index 00000000..5a22ef79 --- /dev/null +++ "b/H0ngJu/\355\236\231/N\353\262\210\354\247\270 \355\201\260 \354\210\230.py" @@ -0,0 +1,19 @@ +import sys +import heapq + +line = int(sys.stdin.readline().strip()) + +heap = [] +heapq.heapify(heap) + +for i in range(line): + data = list(map(int, sys.stdin.readline().strip().split())) + for s in data: + if len(heap) < line: + heapq.heappush(heap, s) + else: + if s > heap[0]: + heapq.heappop(heap) + heapq.heappush(heap, s) + +print(heap[0]) \ No newline at end of file From ecf5ee0116b785ef9d7b8caeb95e171653effc66 Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Sun, 10 Mar 2024 15:55:10 +0900 Subject: [PATCH 14/39] 2024-03-10 --- tgyuuAn/README.md | 1 + ...0\354\204\234 \354\235\264\353\217\231.py" | 0 ...4 \352\261\264\353\204\210\352\270\260.py" | 25 +++++++++++++++++++ 3 files changed, 26 insertions(+) rename "tgyuuAn/\354\235\264\354\247\204 \355\203\220\354\203\211/\353\260\260\354\227\264\354\227\220\354\204\234 \354\235\264\353\217\231.py" => "tgyuuAn/\354\235\264\353\266\204 \355\203\220\354\203\211/\353\260\260\354\227\264\354\227\220\354\204\234 \354\235\264\353\217\231.py" (100%) create mode 100644 "tgyuuAn/\354\235\264\353\266\204 \355\203\220\354\203\211/\354\247\225\352\262\200\353\213\244\353\246\254 \352\261\264\353\204\210\352\270\260.py" diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 530f4f4a..f09fddd1 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -42,4 +42,5 @@ | 38차시 | 2023.02.15 | DP | 피보나치 수 3 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137 | 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 +| 42차시 | 2024.03.10 | 이분 탐색 | 징검다리 건너기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/157 --- diff --git "a/tgyuuAn/\354\235\264\354\247\204 \355\203\220\354\203\211/\353\260\260\354\227\264\354\227\220\354\204\234 \354\235\264\353\217\231.py" "b/tgyuuAn/\354\235\264\353\266\204 \355\203\220\354\203\211/\353\260\260\354\227\264\354\227\220\354\204\234 \354\235\264\353\217\231.py" similarity index 100% rename from "tgyuuAn/\354\235\264\354\247\204 \355\203\220\354\203\211/\353\260\260\354\227\264\354\227\220\354\204\234 \354\235\264\353\217\231.py" rename to "tgyuuAn/\354\235\264\353\266\204 \355\203\220\354\203\211/\353\260\260\354\227\264\354\227\220\354\204\234 \354\235\264\353\217\231.py" diff --git "a/tgyuuAn/\354\235\264\353\266\204 \355\203\220\354\203\211/\354\247\225\352\262\200\353\213\244\353\246\254 \352\261\264\353\204\210\352\270\260.py" "b/tgyuuAn/\354\235\264\353\266\204 \355\203\220\354\203\211/\354\247\225\352\262\200\353\213\244\353\246\254 \352\261\264\353\204\210\352\270\260.py" new file mode 100644 index 00000000..bbe6c556 --- /dev/null +++ "b/tgyuuAn/\354\235\264\353\266\204 \355\203\220\354\203\211/\354\247\225\352\262\200\353\213\244\353\246\254 \352\261\264\353\204\210\352\270\260.py" @@ -0,0 +1,25 @@ +def check(mid, stones, k): + gap = 0 + for stone in stones: + if stone - mid < 0: gap += 1 + else: gap = 0 + + if gap >= k: return False + return True + +def solution(stones, k): + left = -1 + right = 200000001 + answer = 0 + + while left+1 Date: Wed, 13 Mar 2024 21:10:22 +0900 Subject: [PATCH 15/39] 2024-03-13 --- H0ngJu/README.md | 1 + .../\353\254\270\354\240\234\354\247\221.py" | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 "H0ngJu/\355\236\231/\353\254\270\354\240\234\354\247\221.py" diff --git a/H0ngJu/README.md b/H0ngJu/README.md index af4ff40e..ca702888 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -3,5 +3,6 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | | :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | | 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | +| 4차시 | 2024.03.13 | 힙 | [문제집](https://www.acmicpc.net/problem/1766) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/158 | --- diff --git "a/H0ngJu/\355\236\231/\353\254\270\354\240\234\354\247\221.py" "b/H0ngJu/\355\236\231/\353\254\270\354\240\234\354\247\221.py" new file mode 100644 index 00000000..b09a6544 --- /dev/null +++ "b/H0ngJu/\355\236\231/\353\254\270\354\240\234\354\247\221.py" @@ -0,0 +1,32 @@ +import sys +import heapq + +n, m = map(int, sys.stdin.readline().rstrip().split()) + +graph = [[] for _ in range(n+1)] +inDegree = [0 for _ in range(n+1)] +q = [] +answer = [] + +# 입력받아서 넣기 +for _ in range(m): + p1, p2 = map(int, sys.stdin.readline().rstrip().split()) + graph[p1].append(p2) # p1은 p2와 연결된 문제 + inDegree[p2] += 1 # 간선 추가 + +# 진입차수가 0이면 큐에 넣기 +for i in range(1, n+1): + if inDegree[i] == 0: + heapq.heappush(q, i) + +# answer에 넣고, 간선 제거 +while q: + prob = heapq.heappop(q) + answer.append(prob) + for i in graph[prob]: # 간선 제거 & 진입차수 0인 것들 처리 + inDegree[i] -= 1 + if inDegree[i] == 0: + heapq.heappush(q, i) + +for result in answer: + print(result, end=" ") \ No newline at end of file From d5e1b264efdd276896346632179f9065fdda18d1 Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Wed, 13 Mar 2024 22:45:06 +0900 Subject: [PATCH 16/39] 2024-03-13 --- tgyuuAn/README.md | 1 + .../\352\260\234\353\257\270\352\265\264.py" | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 "tgyuuAn/\355\212\270\353\235\274\354\235\264/\352\260\234\353\257\270\352\265\264.py" diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 530f4f4a..2877d797 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -42,4 +42,5 @@ | 38차시 | 2023.02.15 | DP | 피보나치 수 3 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/137 | 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 +| 44차시 | 2023.03.13 | 트라이 | 개미굴 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/159 --- diff --git "a/tgyuuAn/\355\212\270\353\235\274\354\235\264/\352\260\234\353\257\270\352\265\264.py" "b/tgyuuAn/\355\212\270\353\235\274\354\235\264/\352\260\234\353\257\270\352\265\264.py" new file mode 100644 index 00000000..5d33234f --- /dev/null +++ "b/tgyuuAn/\355\212\270\353\235\274\354\235\264/\352\260\234\353\257\270\352\265\264.py" @@ -0,0 +1,48 @@ +import sys + +def input(): return sys.stdin.readline() + +class Node(): + def __init__(self, key): + self.key = key + self.children = {} # 딕셔너리 선언 + +class Tries(): + def __init__(self): + self.head = Node(None) + + def insert(self, informations): + cur_node = self.head + + for info in informations: + # 만약 자식 노드들 중에서 char가 없을 경우 새로운 노드를 만듬 + if info not in cur_node.children: + cur_node.children[info] = Node(info) + + cur_node = cur_node.children[info] + + def search_all(self): + cur_node = self.head + stack = [[cur_node, 0]] + + while stack: + cur_node, depth = stack.pop() + + if cur_node.key != None: + if depth == 1: print(cur_node.key) + else: + for _ in range((depth-1)*2): print("-", end="") + print(cur_node.key) + + for key in sorted(list(cur_node.children.keys()), reverse = True): + stack.append([cur_node.children[key], depth+1]) + + +N = int(input()) +tries = Tries() + +for _ in range(N): + info = input().split()[1:] + tries.insert(info) + +tries.search_all() \ 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 17/39] =?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 84612f0471fae071076dae02e5f05f4a39ba4fe7 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Sat, 16 Mar 2024 22:54:18 +0900 Subject: [PATCH 18/39] 2024-03-16 --- H0ngJu/README.md | 1 + ...24\354\204\270\355\221\270\354\212\244.py" | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 "H0ngJu/\352\265\254\355\230\204/\354\232\224\354\204\270\355\221\270\354\212\244.py" diff --git a/H0ngJu/README.md b/H0ngJu/README.md index af4ff40e..dd774916 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -3,5 +3,6 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | | :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | | 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | +| 5차시 | 2024.03.16 | 구현 | [요세푸스 문제](https://www.acmicpc.net/problem/1158) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/161 | --- diff --git "a/H0ngJu/\352\265\254\355\230\204/\354\232\224\354\204\270\355\221\270\354\212\244.py" "b/H0ngJu/\352\265\254\355\230\204/\354\232\224\354\204\270\355\221\270\354\212\244.py" new file mode 100644 index 00000000..387cd23d --- /dev/null +++ "b/H0ngJu/\352\265\254\355\230\204/\354\232\224\354\204\270\355\221\270\354\212\244.py" @@ -0,0 +1,27 @@ +import sys + +def input(): + return sys.stdin.readline().rstrip() + +def solution(k): + location = 0 + cnt = 0 + + while table: + if cnt == k - 1: + answer.append(table.pop(location)) + location -= 1 # 삭제한 경우에는 위치를 앞으로 이동 + cnt = 0 + else: + cnt += 1 + if len(table) != 0: + location = (location + 1) % len(table) + + return answer + +n, k = map(int, input().split()) +table = [i + 1 for i in range(n)] +answer = [] + +solution(k) +print("<" + ", ".join(map(str, answer)) + ">") \ No newline at end of file From ed9e5aa0c699c065f709a5d47e7ad247efd44158 Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Sun, 17 Mar 2024 00:43:50 +0900 Subject: [PATCH 19/39] 2024-03-16 --- tgyuuAn/README.md | 1 + ...4\355\201\254 \355\212\270\353\246\254.py" | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 "tgyuuAn/\355\212\270\353\235\274\354\235\264/\353\224\224\354\212\244\355\201\254 \355\212\270\353\246\254.py" diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index f608a203..e27b7112 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 +| 45차시 | 2023.03.16 | 트라이 | 트라이 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/162 --- diff --git "a/tgyuuAn/\355\212\270\353\235\274\354\235\264/\353\224\224\354\212\244\355\201\254 \355\212\270\353\246\254.py" "b/tgyuuAn/\355\212\270\353\235\274\354\235\264/\353\224\224\354\212\244\355\201\254 \355\212\270\353\246\254.py" new file mode 100644 index 00000000..db7bf90e --- /dev/null +++ "b/tgyuuAn/\355\212\270\353\235\274\354\235\264/\353\224\224\354\212\244\355\201\254 \355\212\270\353\246\254.py" @@ -0,0 +1,48 @@ +import sys + +def input(): return sys.stdin.readline().rstrip() + +N = int(input()) + +class Node(): + def __init__(self, key): + self.key = key + self.children = {} + +class Tries(): + def __init__(self): + self.head = Node(None) + + def insert(self, path): + now = self.head + directories = path.split("\\") + + for directory in directories: + if directory not in now.children: + now.children[directory] = Node(directory) + + now = now.children[directory] + + def dfs(self, now : Node, depth): + if now.key is not None: + for _ in range(depth): + print(" ", end="") + print(now.key) + + now_children = list(now.children.keys()) + now_children.sort() + + for child in now_children: + self.dfs(now.children[child], depth+1) + + def display_all(self): + now = self.head + self.dfs(now, -1) + +tries = Tries() + +for _ in range(N): + path = input() + tries.insert(path) + +tries.display_all() \ No newline at end of file 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 20/39] 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 d1971b60a273519293c942af47a20ff4cfcc944e Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Tue, 19 Mar 2024 23:50:07 +0900 Subject: [PATCH 21/39] 2024-03-19 --- H0ngJu/README.md | 1 + .../\354\230\244\355\201\260\354\210\230.py" | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 "H0ngJu/\354\230\244\355\201\260\354\210\230.py" diff --git a/H0ngJu/README.md b/H0ngJu/README.md index af4ff40e..9829c739 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -3,5 +3,6 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | | :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | | 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | +| 6차시 | 2024.03.19 | 스택 | [오큰수](https://www.acmicpc.net/problem/17298) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/164 | --- diff --git "a/H0ngJu/\354\230\244\355\201\260\354\210\230.py" "b/H0ngJu/\354\230\244\355\201\260\354\210\230.py" new file mode 100644 index 00000000..a9fbaaee --- /dev/null +++ "b/H0ngJu/\354\230\244\355\201\260\354\210\230.py" @@ -0,0 +1,25 @@ +import sys +from collections import * + +def input(): return sys.stdin.readline().strip() +N = int(input()) + +arr = list(map(int, input().split())) +arr.reverse() +answer = [-1 for _ in range(N)] + +id = 0 + +stack = [] +stack.append((id,arr.pop())) + +while arr: + id += 1 + arr_data = arr.pop() + while stack and stack[-1][1] < arr_data: + index, data = stack.pop() + answer[index] = arr_data + stack.append((id, arr_data)) + +for i in answer: + print(i, end=" ") \ 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 22/39] 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 b484dfa31d7dd64fa9fd5a6c275f57c5470f6773 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Fri, 22 Mar 2024 17:40:14 +0900 Subject: [PATCH 23/39] 2024-03-22 --- ...3 \353\215\224\355\225\230\352\270\260.py" | 26 +++++++++++++++++++ H0ngJu/README.md | 1 + 2 files changed, 27 insertions(+) create mode 100644 "H0ngJu/DP/1,2,3 \353\215\224\355\225\230\352\270\260.py" diff --git "a/H0ngJu/DP/1,2,3 \353\215\224\355\225\230\352\270\260.py" "b/H0ngJu/DP/1,2,3 \353\215\224\355\225\230\352\270\260.py" new file mode 100644 index 00000000..aa703837 --- /dev/null +++ "b/H0ngJu/DP/1,2,3 \353\215\224\355\225\230\352\270\260.py" @@ -0,0 +1,26 @@ +import sys + +def input(): return sys.stdin.readline().strip() + +T = int(input()) + +answer = [] +dp = [0] * (11) + +for index in range(T): + data = int(input()) + + for i in range(1, data + 1): + if i == 1: + dp[i] = 1 + elif i == 2: + dp[i] = 2 + elif i == 3: + dp[i] = 4 + else: + dp[i] = dp[i-1] + dp[i-2] + dp[i-3] + + answer.append(dp[data]) + +for a in answer: + print(a, end=" ") \ No newline at end of file diff --git a/H0ngJu/README.md b/H0ngJu/README.md index af4ff40e..6d6fbf92 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -3,5 +3,6 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | | :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | | 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.22 | DP | [1,2,3 더하기](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/166 | --- From a251e77e56d873678dd88a225df91e23eca0c2a8 Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Fri, 22 Mar 2024 21:47:59 +0900 Subject: [PATCH 24/39] 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 25/39] 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 26/39] 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 27/39] 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 28/39] 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 05dbfff6bc14d106932f04502cb3322d71e1280f Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Thu, 28 Mar 2024 21:29:09 +0900 Subject: [PATCH 29/39] 2024-03-28 --- "H0ngJu/DP/RGB\352\261\260\353\246\254 2.py" | 21 +++++++++++++++++++ H0ngJu/README.md | 17 ++++++++------- .../\354\230\244\355\201\260\354\210\230.py" | 0 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 "H0ngJu/DP/RGB\352\261\260\353\246\254 2.py" rename "H0ngJu/\354\230\244\355\201\260\354\210\230.py" => "H0ngJu/\354\212\244\355\203\235/\354\230\244\355\201\260\354\210\230.py" (100%) diff --git "a/H0ngJu/DP/RGB\352\261\260\353\246\254 2.py" "b/H0ngJu/DP/RGB\352\261\260\353\246\254 2.py" new file mode 100644 index 00000000..3ccfcfe4 --- /dev/null +++ "b/H0ngJu/DP/RGB\352\261\260\353\246\254 2.py" @@ -0,0 +1,21 @@ +import sys + +def input(): return sys.stdin.readline().rstrip() + +N = int(input()) +INF = 1000*1000+1 + +house = [[int(x) for x in input().split()] for _ in range(N)] +cost = INF + +for first_house in range(3): + dp = [[INF] * 3 for _ in range(N)] + dp[0][first_house] = house[0][first_house] + for i in range(1, N): + dp[i][0] = min(dp[i-1][1], dp[i-1][2]) + house[i][0] + dp[i][1] = min(dp[i-1][0], dp[i-1][2]) + house[i][1] + dp[i][2] = min(dp[i-1][0], dp[i-1][1]) + house[i][2] + dp[N-1][first_house] = INF + cost = min(cost, min(dp[N-1])) + +print(cost) \ No newline at end of file diff --git a/H0ngJu/README.md b/H0ngJu/README.md index eea8f055..1d6fdf40 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -1,13 +1,14 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | -| 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 | -| 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 | +| 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 | +| 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 | +| 9차시 | 2024.03.22 | DP | [RGB거리 2](https://www.acmicpc.net/problem/17404) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/172 | --- diff --git "a/H0ngJu/\354\230\244\355\201\260\354\210\230.py" "b/H0ngJu/\354\212\244\355\203\235/\354\230\244\355\201\260\354\210\230.py" similarity index 100% rename from "H0ngJu/\354\230\244\355\201\260\354\210\230.py" rename to "H0ngJu/\354\212\244\355\203\235/\354\230\244\355\201\260\354\210\230.py" From 01fbdd4ab3c182b3b969e3a9e046ca0f3a6cdca7 Mon Sep 17 00:00:00 2001 From: JSPark <48265129+pknujsp@users.noreply.github.com> Date: Fri, 29 Mar 2024 16:54:00 +0900 Subject: [PATCH 30/39] 2024-03-29 --- ...4 \353\247\214\353\223\244\352\270\260.py" | 76 +++++++++++++++++++ pknujsp/README.md | 3 +- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 "pknujsp/BFS/42-\353\213\244\353\246\254 \353\247\214\353\223\244\352\270\260.py" diff --git "a/pknujsp/BFS/42-\353\213\244\353\246\254 \353\247\214\353\223\244\352\270\260.py" "b/pknujsp/BFS/42-\353\213\244\353\246\254 \353\247\214\353\223\244\352\270\260.py" new file mode 100644 index 00000000..a36ea91b --- /dev/null +++ "b/pknujsp/BFS/42-\353\213\244\353\246\254 \353\247\214\353\223\244\352\270\260.py" @@ -0,0 +1,76 @@ +from collections import * + +map_size = int(input()) +matrix = [list(map(int, input().split())) for _ in range(map_size)] + +directions = [(1, 0), (0, -1), (-1, 0), (0, 1)] +island_id = 2 +costs = [[0] * map_size for _ in range(map_size)] + +# 다리를 놓을 위치를 저장할 큐 +bridge_queue = deque() + +# 전체 맵을 순회하면서 각 섬에 ID 부여 +for row in range(map_size): + for col in range(map_size): + + if matrix[row][col] != 1: + continue + + # 현재 칸을 시작으로 하는 섬에 고유 ID 할당 + matrix[row][col] = island_id + queue = deque([(row, col)]) + + # BFS를 통해 같은 섬인 육지에 ID 할당 + while queue: + r, c = queue.popleft() + # 육지 영역은 다리 영역 탐색 시에 제외함 + costs[r][c] = -1 + + for dr, dc in directions: + nr, nc = r + dr, c + dc + + if not 0 <= nr < map_size or not 0 <= nc < map_size: + continue + + # 다른 섬과 연결된 바다 영역에 접근하면 종료 + if 1 < matrix[nr][nc] < island_id: + print(1) + exit() + + # 새로운 육지 발견 시 큐에 추가 + if matrix[nr][nc] == 1: + queue.append((nr, nc)) + # 육지와 바로 맞닿은 바다 영역을 다리 후보로 추가 + elif matrix[nr][nc] == costs[nr][nc] == 0: + bridge_queue.append((nr, nc, 1, island_id)) + + costs[nr][nc] = 1 + matrix[nr][nc] = island_id + + island_id += 1 + +min_cost = int(1e6) + +# 다리 후보 위치를 순회하며 최소 다리 길이 계산 +while bridge_queue: + r, c, cost, curr_island_id = bridge_queue.popleft() + + for dr, dc in directions: + nr, nc = r + dr, c + dc + + if not 0 <= nr < map_size or not 0 <= nc < map_size: + continue + + # 아직 다리가 놓이지 않은 바다 영역이면 + # 다리 길이를 증가시키고 큐에 추가 + if costs[nr][nc] == 0: + bridge_queue.append((nr, nc, cost + 1, curr_island_id)) + + costs[nr][nc] = cost + 1 + matrix[nr][nc] = curr_island_id + # 다른 섬과 연결된 다리 영역에 접근하였다면 최소 비용을 갱신 + elif matrix[nr][nc] > 1 and matrix[nr][nc] != curr_island_id: + min_cost = min(min_cost, cost + costs[nr][nc]) + +print(min_cost) diff --git a/pknujsp/README.md b/pknujsp/README.md index 665f42d8..078a8f94 100644 --- a/pknujsp/README.md +++ b/pknujsp/README.md @@ -42,4 +42,5 @@ | 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) | \ No newline at end of file +| 41차시 | 2024.03.25 | 다익스트라 | [알고스팟](https://www.acmicpc.net/problem/1261) | [#169](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/169) | +| 42차시 | 2024.03.29 | BFS | [다리 만들기](https://www.acmicpc.net/problem/2146) | [#173](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/173) | \ 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 31/39] 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 32/39] 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 --- From 6511bd9222896480ae2b191fbad427b8d0e47133 Mon Sep 17 00:00:00 2001 From: JSPark <48265129+pknujsp@users.noreply.github.com> Date: Wed, 3 Apr 2024 01:28:25 +0900 Subject: [PATCH 33/39] 2024-04-03 --- ...246\254 \353\247\214\353\223\244\352\270\260.py" | 5 +---- pknujsp/README.md | 3 ++- .../43-\354\240\200\354\232\270.py" | 13 +++++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 "pknujsp/\352\267\270\353\246\254\353\224\224/43-\354\240\200\354\232\270.py" diff --git "a/pknujsp/BFS/42-\353\213\244\353\246\254 \353\247\214\353\223\244\352\270\260.py" "b/pknujsp/BFS/42-\353\213\244\353\246\254 \353\247\214\353\223\244\352\270\260.py" index a36ea91b..478f5364 100644 --- "a/pknujsp/BFS/42-\353\213\244\353\246\254 \353\247\214\353\223\244\352\270\260.py" +++ "b/pknujsp/BFS/42-\353\213\244\353\246\254 \353\247\214\353\223\244\352\270\260.py" @@ -24,9 +24,6 @@ # BFS를 통해 같은 섬인 육지에 ID 할당 while queue: r, c = queue.popleft() - # 육지 영역은 다리 영역 탐색 시에 제외함 - costs[r][c] = -1 - for dr, dc in directions: nr, nc = r + dr, c + dc @@ -73,4 +70,4 @@ elif matrix[nr][nc] > 1 and matrix[nr][nc] != curr_island_id: min_cost = min(min_cost, cost + costs[nr][nc]) -print(min_cost) +print(min_cost) \ No newline at end of file diff --git a/pknujsp/README.md b/pknujsp/README.md index 078a8f94..489d3d88 100644 --- a/pknujsp/README.md +++ b/pknujsp/README.md @@ -43,4 +43,5 @@ | 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) | -| 42차시 | 2024.03.29 | BFS | [다리 만들기](https://www.acmicpc.net/problem/2146) | [#173](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/173) | \ No newline at end of file +| 42차시 | 2024.03.29 | BFS | [다리 만들기](https://www.acmicpc.net/problem/2146) | [#173](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/173) | +| 43차시 | 2024.04.03 | 그리디 | [저울](https://www.acmicpc.net/problem/2437) | [#175](https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/175) | \ No newline at end of file diff --git "a/pknujsp/\352\267\270\353\246\254\353\224\224/43-\354\240\200\354\232\270.py" "b/pknujsp/\352\267\270\353\246\254\353\224\224/43-\354\240\200\354\232\270.py" new file mode 100644 index 00000000..8000dc85 --- /dev/null +++ "b/pknujsp/\352\267\270\353\246\254\353\224\224/43-\354\240\200\354\232\270.py" @@ -0,0 +1,13 @@ +N = int(input()) +weights = list(map(int, input().split())) +weights.sort() + +x = 0 +for weight in weights: + # x + 1이 현재 추의 무게보다 작다면, 측정이 불가능함 + if x + 1 < weight: + break + + x += weight + +print(x + 1) \ No newline at end of file From ef65e3117b22ee8391e6d8122afb4e8b0966394a Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Wed, 3 Apr 2024 23:59:35 +0900 Subject: [PATCH 34/39] 2024-04-03 --- ...0\353\260\224\352\274\255\354\247\2104.py" | 33 +++++++++++++++++++ H0ngJu/README.md | 19 ++++++----- 2 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 "H0ngJu/BFS/\354\210\250\353\260\224\352\274\255\354\247\2104.py" diff --git "a/H0ngJu/BFS/\354\210\250\353\260\224\352\274\255\354\247\2104.py" "b/H0ngJu/BFS/\354\210\250\353\260\224\352\274\255\354\247\2104.py" new file mode 100644 index 00000000..d1db02cf --- /dev/null +++ "b/H0ngJu/BFS/\354\210\250\353\260\224\352\274\255\354\247\2104.py" @@ -0,0 +1,33 @@ +import sys +from collections import deque + +def input(): return sys.stdin.readline() + +N, K = map(int, input().split()) + +visited = [0] * 100001 +time = 0 +parent = [-1] * 100001 + +q = deque([N]) +visited[N] = 1 + +while q: + size = len(q) + for _ in range(size): + location = q.popleft() + if location == K: + print(time) + answer = [] + while location != -1: + answer.append(location) + location = parent[location] + answer.reverse() + print(" ".join(map(str, answer))) + break + for next_location in (location + 1, location - 1, location * 2): + if 0 <= next_location <= 100000 and not visited[next_location]: + q.append(next_location) + visited[next_location] = 1 + parent[next_location] = location + time += 1 diff --git a/H0ngJu/README.md b/H0ngJu/README.md index eea8f055..28f281eb 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -1,13 +1,14 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | -| 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 | -| 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 | +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +| :----: | :--------: | :------: | :-----------------------------------------------------------------------------------: | :-------------------------------------------------: | +| 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 | +| 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 | +| 10차시 | 2024.04.03 | BFS | [숨바꼭질 4](https://www.acmicpc.net/problem/13913) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/177 | --- From 27c07988e33648029bc870b7a5d22ce8a6e24802 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Sun, 7 Apr 2024 11:28:50 +0900 Subject: [PATCH 35/39] 2024-04-07 --- H0ngJu/README.md | 19 ++++---- ...4\355\203\225 \352\262\214\354\236\204.py" | 44 +++++++++++++++++++ 2 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 "H0ngJu/\352\265\254\355\230\204/\354\202\254\355\203\225 \352\262\214\354\236\204.py" diff --git a/H0ngJu/README.md b/H0ngJu/README.md index eea8f055..3bfb00f2 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -1,13 +1,14 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | -| 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 | -| 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 | +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +| :----: | :--------: | :------: | :-----------------------------------------------------------------------------------: | :-------------------------------------------------: | +| 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 | +| 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 | +| 11차시 | 2024.04.07 | 구현 | [사탕 게임](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/178 | --- diff --git "a/H0ngJu/\352\265\254\355\230\204/\354\202\254\355\203\225 \352\262\214\354\236\204.py" "b/H0ngJu/\352\265\254\355\230\204/\354\202\254\355\203\225 \352\262\214\354\236\204.py" new file mode 100644 index 00000000..e2c0a578 --- /dev/null +++ "b/H0ngJu/\352\265\254\355\230\204/\354\202\254\355\203\225 \352\262\214\354\236\204.py" @@ -0,0 +1,44 @@ +import sys + +def input(): return sys.stdin.readline().rstrip() + +def eat(row, col): + row_cnt = 0 + col_cnt = 0 + tmp_col = 1 + tmp_row = 1 + for idx in range(N-1): + # 열에서 먹을 때 + if data[row][idx] == data[row][idx+1]: + tmp_col += 1 + col_cnt = max(col_cnt, tmp_col) + else: + tmp_col = 1 + + # 행에서 먹을 때 + if data[idx][col] == data[idx+1][col]: + tmp_row += 1 + row_cnt = max(row_cnt, tmp_row) + else: + tmp_row = 1 + + return max(row_cnt, col_cnt) + + +N = int(input()) +data = [[x for x in input()] for _ in range(N)] +directions = [(0,-1), (0,1), (-1,0),(1,0)] +cnt = 0 + +for i in range(N): + for k in range(N): + for dir in directions: + dx, dy = dir + x = i+dx + y = k+dy + if 0<=x Date: Tue, 9 Apr 2024 12:08:09 +0900 Subject: [PATCH 36/39] 2024-04-09 --- H0ngJu/DFS/ABCDE.py | 43 +++++++++++++++++++++++++++++++++++++++++++ H0ngJu/README.md | 19 ++++++++++--------- 2 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 H0ngJu/DFS/ABCDE.py diff --git a/H0ngJu/DFS/ABCDE.py b/H0ngJu/DFS/ABCDE.py new file mode 100644 index 00000000..913bdcd3 --- /dev/null +++ b/H0ngJu/DFS/ABCDE.py @@ -0,0 +1,43 @@ +import sys + +def input(): return sys.stdin.readline().rstrip() + +# 재귀함수 fr_check +def fr_check(friend, stack): + stack.append(friend) # 현재 친구를 스택에 추가 + print(stack) + + if len(stack) == 5: # 친구 5명 되면 + return stack + + for x in friends[friend]: + if x not in stack: + result = fr_check(x, stack.copy()) # 복사해야 별도의 stack이 만들어져서 전달 가능 + if result is not None: + return result + + return None # stack이 5가 되지 않은 경우 + + +N, M = map(int, input().split()) +friends = [[] for _ in range(N)] #freind[i]에는 i의 친구 담기 +fcheck = 0 +stack = [] + + +for _ in range(M): + f0, f1 = map(int, input().split()) + friends[f0].append(f1) + friends[f1].append(f0) + + +for idx in range(N): + stack = [] + result = fr_check(idx, stack) #idx부터 체크 시작 + if result != None and len(result) == 5: + fcheck = 1 + print("1") + break + +if fcheck == 0: + print(0) \ No newline at end of file diff --git a/H0ngJu/README.md b/H0ngJu/README.md index eea8f055..1da5a7b5 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -1,13 +1,14 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | -| 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 | -| 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 | +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +| :----: | :--------: | :------: | :-----------------------------------------------------------------------------------: | :-------------------------------------------------: | +| 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 | +| 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 | +| 12차시 | 2024.04.09 | DFS | [ABCDE](https://www.acmicpc.net/problem/13023) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/180 | --- From 9024ee4c9a10de791808b5bc074e95d4c6119b48 Mon Sep 17 00:00:00 2001 From: tgyuu-An Date: Mon, 8 Apr 2024 15:40:05 +0900 Subject: [PATCH 37/39] 2024-04-07 --- "tgyuuAn/BFS/\352\263\274\354\231\270\353\247\250.py" | 0 tgyuuAn/README.md | 1 + 2 files changed, 1 insertion(+) create mode 100644 "tgyuuAn/BFS/\352\263\274\354\231\270\353\247\250.py" diff --git "a/tgyuuAn/BFS/\352\263\274\354\231\270\353\247\250.py" "b/tgyuuAn/BFS/\352\263\274\354\231\270\353\247\250.py" new file mode 100644 index 00000000..e69de29b diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 5fd3dcb3..262b42dc 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 +| 51차시 | 2023.04.07 | BFS | 과외맨 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/179 --- From c12d538bfb7aa53652117009eba0efa67540751e Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Mon, 6 May 2024 23:08:33 +0900 Subject: [PATCH 38/39] 2024-05-06 --- ... \352\263\204\353\213\250 \354\210\230.py" | 0 .../\353\246\254\353\252\250\354\273\250.py" | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+) rename "H0ngJu/\354\211\254\354\232\264 \352\263\204\353\213\250 \354\210\230.py" => "H0ngJu/DP/\354\211\254\354\232\264 \352\263\204\353\213\250 \354\210\230.py" (100%) create mode 100644 "H0ngJu/\353\246\254\353\252\250\354\273\250.py" diff --git "a/H0ngJu/\354\211\254\354\232\264 \352\263\204\353\213\250 \354\210\230.py" "b/H0ngJu/DP/\354\211\254\354\232\264 \352\263\204\353\213\250 \354\210\230.py" similarity index 100% rename from "H0ngJu/\354\211\254\354\232\264 \352\263\204\353\213\250 \354\210\230.py" rename to "H0ngJu/DP/\354\211\254\354\232\264 \352\263\204\353\213\250 \354\210\230.py" diff --git "a/H0ngJu/\353\246\254\353\252\250\354\273\250.py" "b/H0ngJu/\353\246\254\353\252\250\354\273\250.py" new file mode 100644 index 00000000..23afbc12 --- /dev/null +++ "b/H0ngJu/\353\246\254\353\252\250\354\273\250.py" @@ -0,0 +1,22 @@ +import sys + +def input(): return sys.stdin.readline().rstrip() + +N = int(input()) +M = int(input()) +btn = list(map(int, input().rsplit())) + +target = abs(N-100) +cnt = target + +for i in range(1000001): + check = True + for str_i in str(i): + if int(str_i) in btn: + check = False + break + + if check: + cnt = min(cnt, abs(i - N)+len(str(i))) + +print(cnt) \ No newline at end of file From 7a2b4fe9b0c5f4a75b80c9d5b2c2f33e3eec4bc8 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Mon, 6 May 2024 23:12:00 +0900 Subject: [PATCH 39/39] 2024-05-06 --- H0ngJu/README.md | 1 + .../\353\246\254\353\252\250\354\273\250.py" | 0 2 files changed, 1 insertion(+) rename "H0ngJu/\353\246\254\353\252\250\354\273\250.py" => "H0ngJu/\354\231\204\354\240\204\355\203\220\354\203\211/\353\246\254\353\252\250\354\273\250.py" (100%) diff --git a/H0ngJu/README.md b/H0ngJu/README.md index 362c56db..44f5ff59 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -14,5 +14,6 @@ | 10차시 | 2024.04.03 | BFS | [숨바꼭질 4](https://www.acmicpc.net/problem/13913) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/177 | | 11차시 | 2024.04.07 | 구현 | [사탕 게임](https://www.acmicpc.net/problem/9095) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/178 | | 12차시 | 2024.04.09 | DFS | [ABCDE](https://www.acmicpc.net/problem/13023) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/180 | +| 13차시 | 2024.05.06 | 완전탐색 | [리모컨](https://www.acmicpc.net/problem/1107) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/181 | --- diff --git "a/H0ngJu/\353\246\254\353\252\250\354\273\250.py" "b/H0ngJu/\354\231\204\354\240\204\355\203\220\354\203\211/\353\246\254\353\252\250\354\273\250.py" similarity index 100% rename from "H0ngJu/\353\246\254\353\252\250\354\273\250.py" rename to "H0ngJu/\354\231\204\354\240\204\355\203\220\354\203\211/\353\246\254\353\252\250\354\273\250.py"