백준 문제 풀이
백준 16943 파이썬 python : 숫자 재배치 @@황소처럼 우직하게@@ permutations 사용해부려
hjp845
2020. 4. 22. 21:07
반응형
뚝딱해부려
10 팩토리얼이 얼말까? 3,628,800
11 팩토리얼이 약 4000만
근데 여기선 10자리수가 최대, 근데 심지어 1,000,000,000 까지니까
실상 9팩토리얼이다.
시간복잡도가 10팩토리얼까지여도 가능한데 9 팩토리얼은 매우 안전빵이다.
import sys
import itertools
input = sys.stdin.readline
a, b = input().split()
b = int(b)
lst = list(map(''.join, list(itertools.permutations(a))))
c = -1
for num in lst:
first = num[0]
num = int(num)
if b >= num and first != '0':
c = max(c, num)
print(c)
반응형