코딩테스트를 위한 백준 문제 풀어보기
import sys
input = sys.stdin.readline
= int(input())
N = list(map(int, input().split()))
num = list(map(int, input().split())) # +, -, *, //
op
= -1e9
maximum = 1e9
minimum
def dfs(depth, total, plus, minus, multiply, divide):
global maximum, minimum
if depth == N:
= max(total, maximum)
maximum = min(total, minimum)
minimum return
if plus:
+ 1, total + num[depth], plus - 1, minus, multiply, divide)
dfs(depth if minus:
+ 1, total - num[depth], plus, minus - 1, multiply, divide)
dfs(depth if multiply:
+ 1, total * num[depth], plus, minus, multiply - 1, divide)
dfs(depth if divide:
+ 1, int(total / num[depth]), plus, minus, multiply, divide - 1)
dfs(depth
1, num[0], op[0], op[1], op[2], op[3])
dfs(print(maximum)
print(minimum)
= list(input())
bracket
= []
stack = 0
answer = 1
tmp
for i in range(len(bracket)):
if bracket[i] == "(":
stack.append(bracket[i])*= 2
tmp
elif bracket[i] == "[":
stack.append(bracket[i])*= 3
tmp
elif bracket[i] == ")":
if not stack or stack[-1] == "[":
= 0
answer break
if bracket[i-1] == "(":
+= tmp
answer
stack.pop()//= 2
tmp
else:
if not stack or stack[-1] == "(":
= 0
answer break
if bracket[i-1] == "[":
+= tmp
answer
stack.pop()//= 3
tmp
if stack:
print(0)
else:
print(answer)
= map(int, input().split())
h, w = list(map(int, input().split()))
world
= 0
ans for i in range(1, w - 1):
= max(world[:i])
left_max = max(world[i+1:])
right_max
= min(left_max, right_max)
compare
if world[i] < compare:
+= compare - world[i]
ans
print(ans)
For attribution, please cite this work as
nackta (2022, June 11). nackta blog: [백준 문제풀이] 약점 체크. Retrieved from https://nackta.github.io/til/2022-06-11-cotepart2/
BibTeX citation
@misc{nackta2022[백준, author = {nackta, }, title = {nackta blog: [백준 문제풀이] 약점 체크}, url = {https://nackta.github.io/til/2022-06-11-cotepart2/}, year = {2022} }