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
    
    
  반응형
    
    
    
  'coding test - python > 백준' 카테고리의 다른 글
| 백준 / [복습] 2839번 설탕배달 - 탐욕 / Python 파이썬 (0) | 2025.04.04 | 
|---|---|
| 백준 / 10819번 차이를 최대로 - 순열 / Python 파이썬 (0) | 2025.04.04 | 
| 백준 / 15649번 N 과 M / Python 파이썬 (0) | 2025.04.04 | 
| 백준 / 1987번 알파벳 / Python 파이썬 (0) | 2025.04.03 | 
| 백준 / 1357번 뒤집힌 덧셈 / Python 파이썬 (0) | 2025.04.03 |