Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions live9/test98/문제1/백한결.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from collections import deque

def main():
N, M = map(int, input().split())
a = list(map(int, input().split()))
print(bfs(N, M, a))

def bfs(N, M, a):
queue = deque()

# 시작위치 0, 눈덩이 크기 1, 시간 0초
queue.append((-1, 1, 0))
maxSize = 1

while queue:
location, size, time = queue.popleft()

# 시간 초과 or 마지막 칸 도달
if time == M or location == N - 1:
maxSize = max(maxSize, size)
continue

# 눈동이를 한 칸 이동시킬 경우
nextLoc1 = location + 1
if nextLoc1 < N:
nextSize1 = size + a[nextLoc1]
queue.append((nextLoc1, nextSize1, time + 1))

# 눈덩이를 두 칸 이동시킬 경우
nextLoc2 = location + 2
if nextLoc2 < N:
nextSize2 = size // 2 + a[nextLoc2]
queue.append((nextLoc2, nextSize2, time + 1))


return maxSize

if __name__ == '__main__':
main()
23 changes: 23 additions & 0 deletions live9/test98/문제2/백한결.py
Original file line number Diff line number Diff line change
@@ -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()
18 changes: 18 additions & 0 deletions live9/test98/문제3/백한결.py
Original file line number Diff line number Diff line change
@@ -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