diff --git a/Seol-Munhyeok/.cph/.ATM.py_0961ba91b3ef35ddeba6bb2caf378d6c.prob b/Seol-Munhyeok/.cph/.ATM.py_0961ba91b3ef35ddeba6bb2caf378d6c.prob new file mode 100644 index 0000000..a55e59e --- /dev/null +++ b/Seol-Munhyeok/.cph/.ATM.py_0961ba91b3ef35ddeba6bb2caf378d6c.prob @@ -0,0 +1 @@ +{"name":"Local: ATM","url":"d:\\AlgoLeadME-15\\AlgoLeadMe-15\\Seol-Munhyeok\\ATM.py","tests":[{"id":1756627725177,"input":"5\n3 1 4 3 2","output":"32"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"d:\\AlgoLeadME-15\\AlgoLeadMe-15\\Seol-Munhyeok\\ATM.py","group":"local","local":true} \ No newline at end of file diff --git "a/Seol-Munhyeok/.cph/.\352\260\234\353\230\245\353\262\214\353\240\210.py_478b34ffa2be96fa5b5b2fbb1687d64c.prob" "b/Seol-Munhyeok/.cph/.\352\260\234\353\230\245\353\262\214\353\240\210.py_478b34ffa2be96fa5b5b2fbb1687d64c.prob" new file mode 100644 index 0000000..bdeb570 --- /dev/null +++ "b/Seol-Munhyeok/.cph/.\352\260\234\353\230\245\353\262\214\353\240\210.py_478b34ffa2be96fa5b5b2fbb1687d64c.prob" @@ -0,0 +1 @@ +{"name":"Local: 개똥벌레","url":"d:\\AlgoLeadME-15\\AlgoLeadMe-15\\Seol-Munhyeok\\개똥벌레.py","tests":[{"id":1756972182171,"input":"14 5\n1\n3\n4\n2\n2\n4\n3\n4\n3\n3\n3\n2\n3\n3","output":"7 2"},{"id":1756972205164,"input":"6 7\n1\n5\n3\n3\n5\n1","output":"2 3"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"d:\\AlgoLeadME-15\\AlgoLeadMe-15\\Seol-Munhyeok\\개똥벌레.py","group":"local","local":true} \ No newline at end of file diff --git "a/Seol-Munhyeok/.cph/.\352\260\234\353\230\245\353\262\214\353\240\2102.py_f7b1bfedf84554024f689b69b61e08ce.prob" "b/Seol-Munhyeok/.cph/.\352\260\234\353\230\245\353\262\214\353\240\2102.py_f7b1bfedf84554024f689b69b61e08ce.prob" new file mode 100644 index 0000000..465ebc2 --- /dev/null +++ "b/Seol-Munhyeok/.cph/.\352\260\234\353\230\245\353\262\214\353\240\2102.py_f7b1bfedf84554024f689b69b61e08ce.prob" @@ -0,0 +1 @@ +{"name":"Local: 개똥벌레2","url":"d:\\AlgoLeadME-15\\AlgoLeadMe-15\\Seol-Munhyeok\\개똥벌레2.py","tests":[{"id":1756973855147,"input":"14 5\n1\n3\n4\n2\n2\n4\n3\n4\n3\n3\n3\n2\n3\n3","output":"7 2"},{"id":1756974701757,"input":"6 7\n1\n5\n3\n3\n5\n1","output":"2 3"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"d:\\AlgoLeadME-15\\AlgoLeadMe-15\\Seol-Munhyeok\\개똥벌레2.py","group":"local","local":true} \ No newline at end of file diff --git "a/Seol-Munhyeok/.cph/.\354\260\250\353\237\211\353\260\260\354\271\230.py_1ee6dc7200a143d3ff95e315a3e7cb91.prob" "b/Seol-Munhyeok/.cph/.\354\260\250\353\237\211\353\260\260\354\271\230.py_1ee6dc7200a143d3ff95e315a3e7cb91.prob" new file mode 100644 index 0000000..bdbc1c9 --- /dev/null +++ "b/Seol-Munhyeok/.cph/.\354\260\250\353\237\211\353\260\260\354\271\230.py_1ee6dc7200a143d3ff95e315a3e7cb91.prob" @@ -0,0 +1 @@ +{"name":"Local: 차량배치","url":"d:\\AlgoLeadME-15\\AlgoLeadMe-15\\Seol-Munhyeok\\차량배치.py","tests":[{"id":1756981134725,"input":"3 3\n1 2\n1 3\n2 3","output":"5"},{"id":1756981248426,"input":"3 2\n1 2\n2 3","output":"7"},{"id":1756981481893,"input":"6 5\n1 2\n1 3\n2 4\n2 5\n3 6","output":"23"},{"id":1756981635073,"input":"1 0\n","output":"1"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"d:\\AlgoLeadME-15\\AlgoLeadMe-15\\Seol-Munhyeok\\차량배치.py","group":"local","local":true} \ No newline at end of file diff --git a/Seol-Munhyeok/ATM.py b/Seol-Munhyeok/ATM.py new file mode 100644 index 0000000..1e06690 --- /dev/null +++ b/Seol-Munhyeok/ATM.py @@ -0,0 +1,10 @@ +n = int(input()) +lst = list(map(int, input().split())) + +lst.sort() +p_sum = [0] * (n + 1) + +for i in range(n): + p_sum[i + 1] = p_sum[i] + lst[i] + +print(sum(p_sum)) diff --git a/Seol-Munhyeok/README.md b/Seol-Munhyeok/README.md index b85607b..b5d3cf1 100644 --- a/Seol-Munhyeok/README.md +++ b/Seol-Munhyeok/README.md @@ -16,4 +16,8 @@ | 20차시 | 2025.08.14 | DP | [코딩 테스트 공부](https://school.programmers.co.kr/learn/courses/30/lessons/118668) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/73 | AlgoLeadMe/AlgoLeadMe-15/pull/67 | | 21차시 | 2025.08.18 | 시뮬레이션, 그리디 | [양궁 대회](https://school.programmers.co.kr/learn/courses/30/lessons/92342) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/75 | -| 22차시 | 2025.08.23 | 그리디, 투 포인터 | [두 큐 합 같게 만들기](https://school.programmers.co.kr/learn/courses/30/lessons/118667) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/79 | \ No newline at end of file +| 22차시 | 2025.08.23 | 그리디, 투 포인터 | [두 큐 합 같게 만들기](https://school.programmers.co.kr/learn/courses/30/lessons/118667) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/79 | +| 23차시 | 2025.09.03 | 수학, 구현 | [책 페이지](https://www.acmicpc.net/problem/1019) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/84 | +| 24차시 | 2025.09.03 | 구현 | [수식 최대화](https://school.programmers.co.kr/learn/courses/30/lessons/67257) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/85 | +| 25차시 | 2025.09.06 | 문자열, 구현 | [방금그곡](https://school.programmers.co.kr/learn/courses/30/lessons/17683) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/86 | +| 26차시 | 2025.09.24 | 구현 | [로또의 최고 순위와 최저 순위](https://school.programmers.co.kr/learn/courses/30/lessons/77484) | https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/93 | diff --git a/Seol-Munhyeok/tempCodeRunnerFile.py b/Seol-Munhyeok/tempCodeRunnerFile.py index aad8b78..d00e753 100644 --- a/Seol-Munhyeok/tempCodeRunnerFile.py +++ b/Seol-Munhyeok/tempCodeRunnerFile.py @@ -1,4 +1 @@ -# 7 6 2 3 15 6 9 8 -# 3 1 1 8 14 7 10 1 -# 6 1 13 6 4 3 11 4 -# 16 1 8 7 5 2 12 2 \ No newline at end of file +down \ No newline at end of file diff --git "a/Seol-Munhyeok/\352\260\234\353\230\245\353\262\214\353\240\210.py" "b/Seol-Munhyeok/\352\260\234\353\230\245\353\262\214\353\240\210.py" new file mode 100644 index 0000000..a9cdfcf --- /dev/null +++ "b/Seol-Munhyeok/\352\260\234\353\230\245\353\262\214\353\240\210.py" @@ -0,0 +1,28 @@ +from bisect import bisect_left + +# 입력 처리 +N, H = map(int, input().split()) +down, up = [], [] +for i in range(N): + h = int(input()) + if i % 2 == 0: + down.append(h) + else: + up.append(h) + +down.sort() +up.sort() + +best = int(1e9) # 파괴해야 하는 장애물의 최솟값 +way = 1 # 구간의 수 +for h in range(1, H + 1): + cnt_down = N // 2 - bisect_left(down, h) + cnt_up = N // 2 - bisect_left(up, H - h + 1) + cnt = cnt_down + cnt_up + if best > cnt: + best = cnt + way = 1 + elif best == cnt: + way += 1 + +print(best, way) diff --git "a/Seol-Munhyeok/\352\260\234\353\230\245\353\262\214\353\240\2102.py" "b/Seol-Munhyeok/\352\260\234\353\230\245\353\262\214\353\240\2102.py" new file mode 100644 index 0000000..f9db7c7 --- /dev/null +++ "b/Seol-Munhyeok/\352\260\234\353\230\245\353\262\214\353\240\2102.py" @@ -0,0 +1,28 @@ +import sys +input = sys.stdin.readline + +N, H = map(int, input().split()) + +# line[i] = 높이 i에서 시작되는 충돌 변화량 +line = [0] * H + +for t in range(N): + h = int(input()) + if t % 2 == 0: # 석순(아래에서 위로 올라옴) + line[0] += 1 + line[h] -= 1 + else: # 종유석(위에서 아래로 내려옴) + line[H - h] += 1 + +# prefix[y] = 높이 y에서 총 충돌 개수 +prefix = [0] * (H + 1) +for i in range(H): + prefix[i + 1] = prefix[i] + line[i] + +prefix = prefix[1:] + +print(line) +print(prefix) +best = min(prefix) +way = prefix.count(best) +print(best, way) diff --git "a/Seol-Munhyeok/\353\241\234\353\230\220\354\235\230 \354\265\234\352\263\240 \354\210\234\354\234\204\354\231\200 \354\265\234\354\240\200 \354\210\234\354\234\204.py" "b/Seol-Munhyeok/\353\241\234\353\230\220\354\235\230 \354\265\234\352\263\240 \354\210\234\354\234\204\354\231\200 \354\265\234\354\240\200 \354\210\234\354\234\204.py" new file mode 100644 index 0000000..f54c1c4 --- /dev/null +++ "b/Seol-Munhyeok/\353\241\234\353\230\220\354\235\230 \354\265\234\352\263\240 \354\210\234\354\234\204\354\231\200 \354\265\234\354\240\200 \354\210\234\354\234\204.py" @@ -0,0 +1,28 @@ +def get_rank(my_nums, win_nums): + my_nums.sort() + win_nums.sort() + count = 0 + i = j = 0 + while i < len(my_nums) and j < len(win_nums): + if my_nums[i] > win_nums[j]: + j += 1 + elif my_nums[i] < win_nums[j]: + i += 1 + else: + count += 1 + i += 1 + j += 1 + + return count + +def solution(lottos, win_nums): + lottos.sort() + zero_count = lottos.count(0) + visible_nums = lottos[zero_count:] + + temp = get_rank(visible_nums, win_nums) + min_rank = 6 if temp <= 1 else 7 - temp + temp += zero_count + max_rank = 6 if temp <= 1 else 7 - temp + + return [max_rank, min_rank] \ No newline at end of file diff --git "a/Seol-Munhyeok/\353\241\234\353\264\207\354\262\255\354\206\214\352\270\260.py" "b/Seol-Munhyeok/\353\241\234\353\264\207\354\262\255\354\206\214\352\270\260.py" new file mode 100644 index 0000000..9608d0c --- /dev/null +++ "b/Seol-Munhyeok/\353\241\234\353\264\207\354\262\255\354\206\214\352\270\260.py" @@ -0,0 +1,52 @@ +def solution(r, c, d, grid): + dirs = [(-1, 0), (0, 1), (1, 0), (0, -1)] + + y, x, cur_dir = r, c, d + cleaned = 0 + + while True: + # 현재 칸 청소 + if grid[y][x] == 0: + grid[y][x] = 2 + cleaned += 1 + + moved = False + + # 왼쪽부터 4방향 검사 + for _ in range(4): + left = (cur_dir + 3) % 4 + dy, dx = dirs[left] + ny, nx = y + dy, x + dx + + if grid[ny][nx] == 0: + # 왼쪽이 미청소면 회전 + 전진 + cur_dir = left + y, x = ny, nx + moved = True + break + else: + # 왼쪽이 아니면 + cur_dir = left + + if moved: + continue + + # 4 방향 모두 불가 -> 뒤로 한 칸 (방향은 유지) + back = (cur_dir + 2) % 4 + dy, dx = dirs[back] + ny, nx = y + dy, x + dx + + # 뒤가 벽이면 종료 + if grid[ny][nx] == 1: + return cleaned + + # 뒤로 이동 (바라보는 방향 cur는 그대로 유지) + y, x = ny, nx + + +# 입력 처리 +n, m = map(int, input().split()) +r, c, d = map(int, input().split()) +grid = [list(map(int, input().split())) for _ in range(n)] + +print(solution(r, c, d, grid)) diff --git "a/Seol-Munhyeok/\353\247\244\354\232\260\354\226\264\353\240\244\354\232\264\353\254\270\354\240\234.py" "b/Seol-Munhyeok/\353\247\244\354\232\260\354\226\264\353\240\244\354\232\264\353\254\270\354\240\234.py" new file mode 100644 index 0000000..a3fde68 --- /dev/null +++ "b/Seol-Munhyeok/\353\247\244\354\232\260\354\226\264\353\240\244\354\232\264\353\254\270\354\240\234.py" @@ -0,0 +1,12 @@ +n, m = map(int, input().split()) + +def solution(n, m): + if n > m: + return 0 + tmp = 1 + for i in range(2, n+1): + tmp = (tmp * i) % m + return tmp + +print(solution(n, m)) + diff --git "a/Seol-Munhyeok/\353\260\251\352\270\210\352\267\270\352\263\241.py" "b/Seol-Munhyeok/\353\260\251\352\270\210\352\267\270\352\263\241.py" new file mode 100644 index 0000000..04ca03e --- /dev/null +++ "b/Seol-Munhyeok/\353\260\251\352\270\210\352\267\270\352\263\241.py" @@ -0,0 +1,32 @@ +def time_to_sec(time): + h, m = time.split(":") + return 60 * int(h) + int(m) + +def convert(score): + lst = [("B#", "b"), ("C#", "c"), ("D#", "d"), ("E#", "e"), ("F#", "f"), ("G#", "g"), ("A#", "a")] + for a, b in lst: + score = score.replace(a, b) + return score + +def convert_2(score, length): + size = len(score) + if size == length: + return score + if size > length: + return score[:length] + if size < length: + return score * (length // size) + score[:length % size] + + +def solution(m, musicinfos): + answer = '(None)' + max_size = -1 + for info in musicinfos: + start, end, title, score = info.split(",") + length = time_to_sec(end) - time_to_sec(start) + m, score = convert(m), convert(score) + if m in convert_2(score, length) and length > max_size: + answer = title + max_size = length + + return answer \ No newline at end of file diff --git "a/Seol-Munhyeok/\354\210\230\354\213\235\354\265\234\353\214\200\355\231\224.py" "b/Seol-Munhyeok/\354\210\230\354\213\235\354\265\234\353\214\200\355\231\224.py" new file mode 100644 index 0000000..bd1b103 --- /dev/null +++ "b/Seol-Munhyeok/\354\210\230\354\213\235\354\265\234\353\214\200\355\231\224.py" @@ -0,0 +1,43 @@ +from itertools import permutations + +def solution(expression): + # 토큰 분리 + token = [] + operators = set() + num = '' + for e in expression: + if e.isdigit(): + num += e + else: + token.append(int(num)) + token.append(e) + operators.add(e) + num = '' + token.append(int(num)) + + max_val = -1 + # 모든 우선 순위 고려 + for ops in permutations(operators): + temp = token[:] + # 연산자 우선 순위대로 처리 + for op in ops: + stack = [] + i = 0 + while i < len(temp): + if temp[i] == op: + val_1 = stack.pop() + val_2 = temp[i + 1] + if op == '+': + stack.append(val_1 + val_2) + elif op == '-': + stack.append(val_1 - val_2) + elif op == '*': + stack.append(val_1 * val_2) + i += 2 + else: + stack.append(temp[i]) + i += 1 + temp = stack + max_val = max(max_val, abs(temp[0])) + + return max_val \ No newline at end of file diff --git "a/Seol-Munhyeok/\354\260\250\353\237\211\353\260\260\354\271\230.py" "b/Seol-Munhyeok/\354\260\250\353\237\211\353\260\260\354\271\230.py" new file mode 100644 index 0000000..44d7df0 --- /dev/null +++ "b/Seol-Munhyeok/\354\260\250\353\237\211\353\260\260\354\271\230.py" @@ -0,0 +1,28 @@ +from collections import defaultdict, deque +import sys + +input = sys.stdin.readline +N, M = map(int, input().split()) +graph = defaultdict(list) +for _ in range(M): + a, b = map(int, input().split()) + graph[a].append(b) + graph[b].append(a) + +visited = [False] * (N+1) +queue = deque() +queue.append(1) +visited[1] = True +answer = 1 + +while queue: + size = len(queue) + answer *= (size + 1) + for _ in range(size): + cur = queue.popleft() + for neighbor in graph[cur]: + if not visited[neighbor]: + queue.append(neighbor) + visited[neighbor] = True + +print((answer - 1) % 1_000_000_007) \ No newline at end of file diff --git "a/Seol-Munhyeok/\354\261\205 \355\216\230\354\235\264\354\247\200.py" "b/Seol-Munhyeok/\354\261\205 \355\216\230\354\235\264\354\247\200.py" new file mode 100644 index 0000000..b8a0ba1 --- /dev/null +++ "b/Seol-Munhyeok/\354\261\205 \355\216\230\354\235\264\354\247\200.py" @@ -0,0 +1,48 @@ +answer = [0] * 10 # 0~9 각 숫자의 총 등장 횟수를 담을 배열 + +start = 1 # 왼쪽 포인터: 아직 세지 않은 최소 숫자 +end = int(input()) # 오른쪽 포인터: 아직 세지 않은 최대 숫자(입력 N) +ten = 1 # 현재 바라보는 자릿값(일=1, 십=10, 백=100, ...) + +# 숫자 n이 지금 바라보는 자릿값(ten=1,10,100,...)에서 +# '접두사'로서 기여하는 고정 등장 횟수를 answer에 더한다. +# 예를들어 calc(12345, 1)은 answer[5], answer[4], ... answer[1]에 +1 +# +ten을 하는 이유는 현재 자리 아래쪽에는 항상 ten가지(0..ten-1)의 조합이 깔리므로, +# 그 자리의 같은 숫자 d가 블록 안에서 정확히 ten번 등장하기 때문. +def calc(n, ten): + while n > 0: + answer[n % 10] += ten + n //= 10 + +# 바깥 while 한 바퀴 = 자릿값 'ten' 하나를 완전히 처리 +while start <= end: + # [1] 왼쪽 모서리 정리: start를 '...0'으로 맞출 때까지 개별 처리 + while start % 10 != 0 and start <= end: + calc(start, ten) + start += 1 + if start > end: break # 다 끝나면 종료 + + # [2] 오른쪽 모서리 정리: end를 '...9'로 맞출 때까지 개별 처리 + while end % 10 != 9 and start <= end: + calc(end, ten) + end -= 1 + + # 여기까지 오면 [start, end]는 현재 자리에서 + # 정확히 '...0 ~ ...9'가 반복되는 '완전 주기 구간'이 됨. + + # [3] 가운데 완전 주기 한 번에 더하기 + # cnt = 현재 자리에서 서로 다른 '접두사' 개수 + # (접두사 하나마다 0~9 각 숫자가 하위 ten가지와 결합하므로 + # 각 숫자가 정확히 'ten'번씩 등장) + cnt = (end // 10) - (start) // 10 + 1 + for d in range(0, 10): + answer[d] += cnt * ten + + # [4] 한 자리 올림: 현재 자리 처리를 끝냈으니 윗자리로 이동 + start //= 10 + end //= 10 + ten *= 10 + +# 결과 출력 +for d in range(0, 10): + print(answer[d], end=' ') diff --git "a/Seol-Munhyeok/\355\206\240\353\247\210\355\206\240.py" "b/Seol-Munhyeok/\355\206\240\353\247\210\355\206\240.py" new file mode 100644 index 0000000..3fcf980 --- /dev/null +++ "b/Seol-Munhyeok/\355\206\240\353\247\210\355\206\240.py" @@ -0,0 +1,37 @@ +from collections import deque +import sys + +m, n = map(int, input().split()) +arr = [] +dy, dx = [-1, 0, 1, 0], [0, 1, 0, -1] +queue = deque() + +# 입력 처리, 1인 좌표 저장 +for i in range(n): + row = [] + for j, val in enumerate(map(int, input().split())): + row.append(val) + if val == 1: + queue.append((i, j)) + arr.append(row) + +# BFS +while queue: + y, x = queue.popleft() + for i in range(4): + ny, nx = y + dy[i], x + dx[i] + if 0 <= ny < n and 0 <= nx < m and arr[ny][nx] == 0: + arr[ny][nx] = arr[y][x] + 1 + queue.append((ny, nx)) + +# 정답 찾기 +answer = -1e9 +for i in range(n): + for j in range(m): + if arr[i][j] == 0: + print(-1) + sys.exit() + if arr[i][j] > answer: + answer = arr[i][j] + +print(answer - 1)