[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ํ๊ฒ ๋๋ฒ / Python
๐ Problem Solving/Programmers
import sys
from itertools import product
input = sys.stdin.readline
target = int(input())
numbers = list(map(int, input().split()))
def solution(numbers, target):
i = [(x, -x) for x in numbers]
j = list(map(sum, product(*i)))
return j.count(target)
print(solution(numbers, target))
ํด์ค
i๋ numbers์ ์๋ ๊ฐ ์์ ์์์ ์์ ๊ฐ์ ํํ๋ก ์ ์ฅํ ๋ฆฌ์คํธ๋ค.
product๋ฅผ ์ด์ฉํด i์ ๋ค์ด์๋ ๋ฐ์ดํฐ๋ค์ ๊ณฑ์งํฉ์ ๊ตฌํด์ค๋ค.
๊ณฑ์งํฉ๋ค์ ํฉ์ ๊ตฌํด target๊ณผ ๊ฐ์ ์์ ๊ฐ์๋ฅผ ๋ฆฌํดํ๋ค.
'๐ Problem Solving > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ํ๋ฆฐํฐ / Python (0) | 2021.06.02 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ์ ํ๋ฒํธ ๋ชฉ๋ก / Python (0) | 2021.06.02 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ๋ ๋งต๊ฒ / Python (0) | 2021.06.02 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv2] ๊ธฐ๋ฅ๊ฐ๋ฐ (0) | 2021.06.02 |
[ํ๋ก๊ทธ๋๋จธ์ค-Lv1] [1์ฐจ] ๋น๋ฐ์ง๋ / Python (0) | 2021.06.02 |