Skip to content

Commit 730023f

Browse files
committed
90차 1번 문제풀이
1 parent 46ecf1d commit 730023f

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

live9/test99/문제1/백유진.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
n = int(input())
2+
arr = list(map(int, input().split()))
3+
op = list(map(int, input().split()))
4+
5+
def dfs(start_index, start_val, plus, minus, mul, div):
6+
stack = [(start_index, start_val, plus, minus, mul, div)]
7+
max_result = -float('inf')
8+
min_result = float('inf')
9+
10+
while stack:
11+
index, current, p, m, mu, d = stack.pop()
12+
if index == n:
13+
max_result = max(max_result, current)
14+
min_result = min(min_result, current)
15+
continue
16+
17+
num = arr[index]
18+
19+
if p:
20+
stack.append((index + 1, current + num, p - 1, m, mu, d))
21+
if m:
22+
stack.append((index + 1, current - num, p, m - 1, mu, d))
23+
if mu:
24+
stack.append((index + 1, current * num, p, m, mu - 1, d))
25+
if d:
26+
if current < 0:
27+
next_val = -(-current // num)
28+
else:
29+
next_val = current // num
30+
stack.append((index + 1, next_val, p, m, mu, d - 1))
31+
32+
return max_result, min_result
33+
34+
max_val, min_val = dfs(1, arr[0], *op)
35+
36+
print(max_val)
37+
print(min_val)

0 commit comments

Comments
 (0)