Skip to content

Commit f1dac0e

Browse files
Merge pull request #659 from Yujin-Baek/main
[백유진] 99차 라이브 코테 제출
2 parents b73d793 + f3bbf04 commit f1dac0e

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
print(max_val)
36+
print(min_val)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from itertools import permutations
2+
n, m = map(int, input().split())
3+
arr = list(map(int, input().split()))
4+
5+
result = []
6+
for p in permutations(arr, m):
7+
result.append(p)
8+
9+
result.sort()
10+
11+
for r in result:
12+
print(*r)

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def solution(s):
2+
answer = 0
3+
4+
for i in range(len(s)):
5+
ns = s[i:] + s[:i]
6+
7+
stack = []
8+
isValid = True
9+
10+
for n in ns:
11+
if n == '(' or n == '{' or n == '[':
12+
stack.append(n)
13+
else:
14+
if not stack:
15+
isValid = False
16+
break
17+
top = stack[-1]
18+
if n == ')' and top == '(' or n == '}' and top == '{' or n == ']' and top == '[':
19+
stack.pop()
20+
else:
21+
isValid = False
22+
break
23+
if isValid and not stack:
24+
answer += 1
25+
26+
return answer

0 commit comments

Comments
 (0)