[백준] 14225번 부분수열의 합

거북이·2023년 2월 1일
0

백준[실버1]

목록 보기
16/67
post-thumbnail

💡문제접근

  • combinations를 이용하고 중복을 제거하기 위해 set을 사용했다.

💡코드(메모리 : 106380KB, 시간 : 716ms)

from itertools import combinations
import sys
input = sys.stdin.readline

N = int(input().strip())
li = list(map(int, input().strip().split()))

result = []
for i in range(1, N+1):
    temp = list(combinations(li, i))
    for t in temp:
        result.append(sum(t))

result = list(set(result))
result.sort()
j = 1
for i in result:
    if j != i:
        break
    j += 1
print(j)

💡소요시간 : 8m

0개의 댓글