From 3d10b0299c0f71f9a8cea8b7279b3ebc989ec5a8 Mon Sep 17 00:00:00 2001 From: hangyeol Date: Mon, 24 Mar 2025 20:14:16 +0900 Subject: [PATCH 1/4] =?UTF-8?q?98=EC=B0=A8=203=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\355\225\234\352\262\260.py" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 "live9/test98/\353\254\270\354\240\2343/\353\260\261\355\225\234\352\262\260.py" diff --git "a/live9/test98/\353\254\270\354\240\2343/\353\260\261\355\225\234\352\262\260.py" "b/live9/test98/\353\254\270\354\240\2343/\353\260\261\355\225\234\352\262\260.py" new file mode 100644 index 00000000..21347cc3 --- /dev/null +++ "b/live9/test98/\353\254\270\354\240\2343/\353\260\261\355\225\234\352\262\260.py" @@ -0,0 +1,18 @@ +def solution(prices): + answer = [0] * len(prices) + + stack = [] + + for i, price in enumerate(prices): + # 가격이 떨어지는 순간을 찾고 그 때까지의 시간을 계산 + while stack and prices[stack[-1]] > price: + j = stack.pop() + answer[j] = i - j + stack.append(i) + + # for문이 끝난 후 떨어지지 않은 가격 + while stack: + j = stack.pop() + answer[j] = len(prices) - (j + 1) + + return answer \ No newline at end of file From ef7a0c04fa37aa18164a496d145787863ef9af8b Mon Sep 17 00:00:00 2001 From: hangyeol Date: Mon, 24 Mar 2025 20:14:24 +0900 Subject: [PATCH 2/4] =?UTF-8?q?98=EC=B0=A8=201=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\355\225\234\352\262\260.py" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "live9/test98/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" diff --git "a/live9/test98/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" "b/live9/test98/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" new file mode 100644 index 00000000..d657827a --- /dev/null +++ "b/live9/test98/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" @@ -0,0 +1,51 @@ +from collections import deque + +def main(): + N, M = map(int, input().split()) + a = list(map(int, input().strip().split()))[:N] + + print(bfs(N, M, a)) + + +def bfs(N, M, a): + queue = deque() + + # 시작위치 0, 눈덩이 크기 1, 시간 0초 + queue.append((0, 1, 0)) + + visited = set() + visited.add((0, 1, 0)) + + maxSize = 1 + + while queue: + location, size, time = queue.popleft() + + maxSize = max(maxSize, size) + + if time == M: + continue + + # 눈동이를 한 칸 이동시킬 경우 + nextLocation = location + 1 + if nextLocation < N: + plusSize = size + a[nextLocation] + current = (nextLocation, plusSize, time+1) + if current not in visited: + visited.add(current) + queue.append(current) + + # 눈덩이를 두 칸 이동시킬 경우 + nextLocation = location + 2 + if nextLocation < N: + plusSize = size // 2 + a[nextLocation] + current = (nextLocation, plusSize, time+1) + if current not in visited: + visited.add(current) + queue.append(current) + + return maxSize + + +if __name__ == '__main__': + main() \ No newline at end of file From aeafd0c300f8cde2a1854235754471d05ef3efcc Mon Sep 17 00:00:00 2001 From: hangyeol Date: Wed, 26 Mar 2025 13:00:22 +0900 Subject: [PATCH 3/4] =?UTF-8?q?98=EC=B0=A8=201=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\355\225\234\352\262\260.py" | 40 +++++++------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git "a/live9/test98/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" "b/live9/test98/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" index d657827a..c2c58507 100644 --- "a/live9/test98/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" +++ "b/live9/test98/\353\254\270\354\240\2341/\353\260\261\355\225\234\352\262\260.py" @@ -2,50 +2,38 @@ def main(): N, M = map(int, input().split()) - a = list(map(int, input().strip().split()))[:N] - + a = list(map(int, input().split())) print(bfs(N, M, a)) - def bfs(N, M, a): queue = deque() # 시작위치 0, 눈덩이 크기 1, 시간 0초 - queue.append((0, 1, 0)) - - visited = set() - visited.add((0, 1, 0)) - + queue.append((-1, 1, 0)) maxSize = 1 while queue: location, size, time = queue.popleft() - maxSize = max(maxSize, size) - - if time == M: + # 시간 초과 or 마지막 칸 도달 + if time == M or location == N - 1: + maxSize = max(maxSize, size) continue # 눈동이를 한 칸 이동시킬 경우 - nextLocation = location + 1 - if nextLocation < N: - plusSize = size + a[nextLocation] - current = (nextLocation, plusSize, time+1) - if current not in visited: - visited.add(current) - queue.append(current) + nextLoc1 = location + 1 + if nextLoc1 < N: + nextSize1 = size + a[nextLoc1] + queue.append((nextLoc1, nextSize1, time + 1)) # 눈덩이를 두 칸 이동시킬 경우 - nextLocation = location + 2 - if nextLocation < N: - plusSize = size // 2 + a[nextLocation] - current = (nextLocation, plusSize, time+1) - if current not in visited: - visited.add(current) - queue.append(current) + nextLoc2 = location + 2 + if nextLoc2 < N: + nextSize2 = size // 2 + a[nextLoc2] + queue.append((nextLoc2, nextSize2, time + 1)) - return maxSize + return maxSize if __name__ == '__main__': main() \ No newline at end of file From e227274cde3ff56f134855e4a8734ee1e7f04d32 Mon Sep 17 00:00:00 2001 From: hangyeol Date: Wed, 26 Mar 2025 13:00:31 +0900 Subject: [PATCH 4/4] =?UTF-8?q?98=EC=B0=A8=202=EB=B2=88=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\353\260\261\355\225\234\352\262\260.py" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "live9/test98/\353\254\270\354\240\2342/\353\260\261\355\225\234\352\262\260.py" diff --git "a/live9/test98/\353\254\270\354\240\2342/\353\260\261\355\225\234\352\262\260.py" "b/live9/test98/\353\254\270\354\240\2342/\353\260\261\355\225\234\352\262\260.py" new file mode 100644 index 00000000..460f4506 --- /dev/null +++ "b/live9/test98/\353\254\270\354\240\2342/\353\260\261\355\225\234\352\262\260.py" @@ -0,0 +1,23 @@ +from itertools import permutations + +def main(): + x = str(input().strip()) + + # 모든 순열 생성 + perm = set(permutations(x)) + + # 가능한 후보 중 x보다 큰 수 + candidates = [] + for p in perm: + numStr = ''.join(p) + num = int(numStr) + if num > int(x): + candidates.append(num) + + if candidates: + print(min(candidates)) + else: + print(0) + +if __name__ == "__main__": + main() \ No newline at end of file