coding test - python/백준

백준 / 2529번 부등호 - 순열 / Python 파이썬

sillon 2025. 4. 4. 12:50
728x90
반응형

 

*문제 출처는 백준에 있습니다.

문제 제목: 2529번 부등호

문제 사이트: https://www.acmicpc.net/problem/2529


나의 풀이

a = int(input())
arr = list(input().split())

max_ = '-1'
min_ = '9999999999999'

visited = [False] * 10
lst = [i for i in range(10)]
def calculaion(lst):
    idx = 0
    for i in range(1,len(lst)):
        if arr[idx] == '<' and int(lst[i - 1]) < int(lst[i]):
            idx += 1
            continue
        elif arr[idx] == '>' and int(lst[i - 1]) > int(lst[i]):
            idx += 1
            continue
        else:
            return False

    return True

def permutation(n,new_lst):
    global visited, max_, min_
    if len(new_lst) == n:
        if calculaion(new_lst):
            if int(max_) < int(new_lst):
                max_ = new_lst
            if int(min_) > int(new_lst):
                min_ = new_lst
        return

    for i in range(len(lst)):
        if visited[i] == False:
            visited[i] = True
            new_lst += str(lst[i])
            permutation(n,new_lst)
            new_lst = new_lst[:-1]
            visited[i] = False

permutation(a+1,'')

print(max_)
print(min_)

 


※ 알아야 할 것

- 그냥 itertools 썼다면 뭔가 시간초과 났을거같다

- 출력 유의해서 보고 str로 했음

728x90
반응형