Baekjoon #15658

Baekjoon #15658

1개의 풀이 · Python

문제 원문 보기 ↗

SOLUTION INFO

Python · main.py

main.py
import sys
from collections import deque

def input():
    return sys.stdin.readline().rstrip()

def DFS(ans):
    global MIN, MAX
    if not arr:
        MIN = min(MIN, ans)
        MAX = max(MAX, ans)
        return
    for i in range(4):
        if oper[i] > 0:
            oper[i] -= 1
            first = arr[0]
            if i == 0:
                DFS(ans+arr.popleft())
            elif i == 1:
                DFS(ans-arr.popleft())
            elif i == 2:
                DFS(ans*arr.popleft())
            elif i == 3:
                if ans < 0 and arr[0] > 0 or ans > 0 and arr[0] < 0:
                    div = abs(ans) // abs(arr.popleft())
                    DFS(-div)
                else:
                    DFS(ans//arr.popleft())
            arr.appendleft(first)
            oper[i] += 1

N = int(input())
arr = deque(list(map(int, input().split())))
oper = list(map(int, input().split()))
MIN = 1e9+1
MAX = -1e9-1
DFS(arr.popleft())
print(MAX)
print(MIN)

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.