ps | |
---|---|
링크 | programmers.co.kr/… |
출처 | 프로그래머스 |
문제 번호 | 77486 |
문제명 | 다단계 칫솔 판매 |
레벨 | Level 3 |
분류 |
트리 |
시간복잡도 | O(n+m) |
인풋사이즈 | n<=10000, m<=100000 |
사용한 언어 | Python |
해결날짜 | 2021/07/06 |
출처 |
ps:problems:programmers:2021_dev-matching_-_웹_백엔드_개발자_상반기 |
"""Solution code for "Programmers 77486. 다단계 칫솔 판매".
- Problem link: https://programmers.co.kr/learn/courses/30/lessons/77486
- Solution link: http://www.teferi.net/ps/problems/programmers/77486
"""
import collections
COST = 100
def solution(enroll, referral, seller, amount):
parents = {child: parent for child, parent in zip(enroll, referral)}
parents['-'] = '-'
profits = collections.defaultdict(int)
for s, a in zip(seller, amount):
profit = a * COST
member = s
while profit > 0:
profit_to_referral = profit // 10
profits[member] += profit - profit_to_referral
profit, member = profit_to_referral, parents[member]
return [profits[x] for x in enroll]