[level 2] Title: 이모티콘 할인행사, Time: 1866.42 ms, Memory: 10.2 MB -BaekjoonHub
This commit is contained in:
232
프로그래머스/2/150368. 이모티콘 할인행사/README.md
Normal file
232
프로그래머스/2/150368. 이모티콘 할인행사/README.md
Normal file
@@ -0,0 +1,232 @@
|
||||
# [level 2] 이모티콘 할인행사 - 150368
|
||||
|
||||
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/150368)
|
||||
|
||||
### 성능 요약
|
||||
|
||||
메모리: 10.2 MB, 시간: 1866.42 ms
|
||||
|
||||
### 구분
|
||||
|
||||
코딩테스트 연습 > 2023 KAKAO BLIND RECRUITMENT
|
||||
|
||||
### 채점결과
|
||||
|
||||
정확성: 100.0<br/>합계: 100.0 / 100.0
|
||||
|
||||
### 제출 일자
|
||||
|
||||
2025년 02월 16일 14:16:45
|
||||
|
||||
### 문제 설명
|
||||
|
||||
<p>카카오톡에서는 이모티콘을 무제한으로 사용할 수 있는 이모티콘 플러스 서비스 가입자 수를 늘리려고 합니다.<br>
|
||||
이를 위해 카카오톡에서는 이모티콘 할인 행사를 하는데, 목표는 다음과 같습니다.</p>
|
||||
|
||||
<ol>
|
||||
<li>이모티콘 플러스 서비스 가입자를 최대한 늘리는 것.</li>
|
||||
<li>이모티콘 판매액을 최대한 늘리는 것.</li>
|
||||
</ol>
|
||||
|
||||
<p><strong><u>1번 목표가 우선이며, 2번 목표가 그 다음입니다.</u></strong></p>
|
||||
|
||||
<p>이모티콘 할인 행사는 다음과 같은 방식으로 진행됩니다.</p>
|
||||
|
||||
<ul>
|
||||
<li><code>n</code>명의 카카오톡 사용자들에게 이모티콘 <code>m</code>개를 할인하여 판매합니다.</li>
|
||||
<li>이모티콘마다 할인율은 다를 수 있으며, 할인율은 10%, 20%, 30%, 40% 중 하나로 설정됩니다.</li>
|
||||
</ul>
|
||||
|
||||
<p>카카오톡 사용자들은 다음과 같은 기준을 따라 이모티콘을 사거나, 이모티콘 플러스 서비스에 가입합니다.</p>
|
||||
|
||||
<ul>
|
||||
<li>각 사용자들은 자신의 기준에 따라 일정 비율 이상 할인하는 이모티콘을 모두 구매합니다.</li>
|
||||
<li>각 사용자들은 자신의 기준에 따라 이모티콘 구매 비용의 합이 일정 가격 이상이 된다면, 이모티콘 구매를 모두 취소하고 이모티콘 플러스 서비스에 가입합니다.</li>
|
||||
</ul>
|
||||
|
||||
<p>다음은 2명의 카카오톡 사용자와 2개의 이모티콘이 있을때의 예시입니다.</p>
|
||||
<table class="table">
|
||||
<thead><tr>
|
||||
<th>사용자</th>
|
||||
<th>비율</th>
|
||||
<th>가격</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr>
|
||||
<td>1</td>
|
||||
<td>40</td>
|
||||
<td>10,000</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>25</td>
|
||||
<td>10,000</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table><table class="table">
|
||||
<thead><tr>
|
||||
<th>이모티콘</th>
|
||||
<th>가격</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr>
|
||||
<td>1</td>
|
||||
<td>7,000</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>9,000</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>1번 사용자는 40%이상 할인하는 이모티콘을 모두 구매하고, 이모티콘 구매 비용이 10,000원 이상이 되면 이모티콘 구매를 모두 취소하고 이모티콘 플러스 서비스에 가입합니다.<br>
|
||||
2번 사용자는 25%이상 할인하는 이모티콘을 모두 구매하고, 이모티콘 구매 비용이 10,000원 이상이 되면 이모티콘 구매를 모두 취소하고 이모티콘 플러스 서비스에 가입합니다.</p>
|
||||
|
||||
<p>1번 이모티콘의 가격은 7,000원, 2번 이모티콘의 가격은 9,000원입니다.</p>
|
||||
|
||||
<p>만약, 2개의 이모티콘을 모두 40%씩 할인한다면, 1번 사용자와 2번 사용자 모두 1,2번 이모티콘을 구매하게 되고, 결과는 다음과 같습니다.</p>
|
||||
<table class="table">
|
||||
<thead><tr>
|
||||
<th>사용자</th>
|
||||
<th>구매한 이모티콘</th>
|
||||
<th>이모티콘 구매 비용</th>
|
||||
<th>이모티콘 플러스 서비스 가입 여부</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr>
|
||||
<td>1</td>
|
||||
<td>1, 2</td>
|
||||
<td>9,600</td>
|
||||
<td>X</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>1, 2</td>
|
||||
<td>9,600</td>
|
||||
<td>X</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>이모티콘 플러스 서비스 가입자는 0명이 늘어나고 이모티콘 판매액은 19,200원이 늘어납니다.</p>
|
||||
|
||||
<p>하지만, 1번 이모티콘을 30% 할인하고 2번 이모티콘을 40% 할인한다면 결과는 다음과 같습니다.</p>
|
||||
<table class="table">
|
||||
<thead><tr>
|
||||
<th>사용자</th>
|
||||
<th>구매한 이모티콘</th>
|
||||
<th>이모티콘 구매 비용</th>
|
||||
<th>이모티콘 플러스 서비스 가입 여부</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr>
|
||||
<td>1</td>
|
||||
<td>2</td>
|
||||
<td>5,400</td>
|
||||
<td>X</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>1, 2</td>
|
||||
<td>10,300</td>
|
||||
<td>O</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>2번 사용자는 이모티콘 구매 비용을 10,000원 이상 사용하여 이모티콘 구매를 모두 취소하고 이모티콘 플러스 서비스에 가입하게 됩니다.<br>
|
||||
따라서, 이모티콘 플러스 서비스 가입자는 1명이 늘어나고 이모티콘 판매액은 5,400원이 늘어나게 됩니다.</p>
|
||||
|
||||
<p>카카오톡 사용자 <code>n</code>명의 구매 기준을 담은 2차원 정수 배열 <code>users</code>, 이모티콘 <code>m</code>개의 정가를 담은 1차원 정수 배열 <code>emoticons</code>가 주어집니다. 이때, 행사 목적을 최대한으로 달성했을 때의 이모티콘 플러스 서비스 가입 수와 이모티콘 매출액을 1차원 정수 배열에 담아 return 하도록 solution 함수를 완성해주세요.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<h5>제한사항</h5>
|
||||
|
||||
<ul>
|
||||
<li>1 ≤ <code>users</code>의 길이 = <code>n</code> ≤ 100
|
||||
|
||||
<ul>
|
||||
<li><code>users</code>의 원소는 [<code>비율</code>, <code>가격</code>]의 형태입니다.</li>
|
||||
<li><code>users[i]</code>는 <code>i+1</code>번 고객의 구매 기준을 의미합니다.</li>
|
||||
<li><code>비율</code>% 이상의 할인이 있는 이모티콘을 모두 구매한다는 의미입니다.
|
||||
|
||||
<ul>
|
||||
<li>1 ≤ <code>비율</code> ≤ 40</li>
|
||||
</ul></li>
|
||||
<li><code>가격</code>이상의 돈을 이모티콘 구매에 사용한다면, 이모티콘 구매를 모두 취소하고 이모티콘 플러스 서비스에 가입한다는 의미입니다.
|
||||
|
||||
<ul>
|
||||
<li>100 ≤ <code>가격</code> ≤ 1,000,000</li>
|
||||
<li><code>가격</code>은 100의 배수입니다.</li>
|
||||
</ul></li>
|
||||
</ul></li>
|
||||
<li>1 ≤ <code>emoticons</code>의 길이 = <code>m</code> ≤ 7
|
||||
|
||||
<ul>
|
||||
<li><code>emoticons[i]</code>는 <code>i+1</code>번 이모티콘의 정가를 의미합니다.</li>
|
||||
<li>100 ≤ <code>emoticons</code>의 원소 ≤ 1,000,000</li>
|
||||
<li><code>emoticons</code>의 원소는 100의 배수입니다.</li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
|
||||
<hr>
|
||||
|
||||
<h5>입출력 예</h5>
|
||||
<table class="table">
|
||||
<thead><tr>
|
||||
<th>users</th>
|
||||
<th>emoticons</th>
|
||||
<th>result</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr>
|
||||
<td>[[40, 10000], [25, 10000]]</td>
|
||||
<td>[7000, 9000]</td>
|
||||
<td>[1, 5400]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>[[40, 2900], [23, 10000], [11, 5200], [5, 5900], [40, 3100], [27, 9200], [32, 6900]]</td>
|
||||
<td>[1300, 1500, 1600, 4900]</td>
|
||||
<td>[4, 13860]</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr>
|
||||
|
||||
<h5>입출력 예 설명</h5>
|
||||
|
||||
<p><strong>입출력 예 #1</strong></p>
|
||||
|
||||
<p>문제의 예시와 같습니다.</p>
|
||||
|
||||
<p><strong>입출력 예 #2</strong></p>
|
||||
|
||||
<p>다음과 같이 할인하는 것이 이모티콘 플러스 서비스 가입자를 최대한 늘리면서, 이모티콘 판매액 또한 최대로 늘리는 방법입니다.</p>
|
||||
<table class="table">
|
||||
<thead><tr>
|
||||
<th>이모티콘</th>
|
||||
<th>할인율</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr>
|
||||
<td>1</td>
|
||||
<td>40</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>40</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td>20</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>4</td>
|
||||
<td>40</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>위와 같이 할인하면 4명의 이모티콘 플러스 가입자와 13,860원의 판매액을 달성할 수 있습니다. 다른 할인율을 적용하여 이모티콘을 판매할 수 있지만 이보다 이모티콘 플러스 서비스 가입자를 최대한 늘리면서, 이모티콘 판매액 또한 최대로 늘리는 방법은 없습니다.<br>
|
||||
따라서, [4, 13860]을 return 하면 됩니다.</p>
|
||||
|
||||
|
||||
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
|
||||
59
프로그래머스/2/150368. 이모티콘 할인행사/이모티콘 할인행사.py
Normal file
59
프로그래머스/2/150368. 이모티콘 할인행사/이모티콘 할인행사.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from collections import defaultdict
|
||||
|
||||
def DFS(idx, config, emoji_count, poss_ratio):
|
||||
# 기저 조건: 모든 이모티콘에 대해 할인율을 정했다면
|
||||
if idx == emoji_count:
|
||||
evaluate_config(config) # 이 할인율 조합에 대해 사용자 시뮬레이션
|
||||
return
|
||||
|
||||
# 백트래킹: 각 이모티콘에 대해 가능한 모든 할인율 시도
|
||||
for discount in poss_ratio:
|
||||
config.append(discount) # 현재 이모티콘에 discount 할당
|
||||
DFS(idx + 1, config, emoji_count, poss_ratio) # 다음 이모티콘으로 진행
|
||||
config.pop() # 할당 취소(백트래킹)
|
||||
|
||||
|
||||
# 전역 변수 (최종 결과)
|
||||
max_plus = 0
|
||||
max_sales = 0
|
||||
|
||||
def evaluate_config(config):
|
||||
global max_plus, max_sales
|
||||
plus_count = 0
|
||||
sales = 0
|
||||
# 각 사용자를 순회
|
||||
for min_discount, price_threshold in users: # users는 전역 또는 매개변수로 전달
|
||||
total_cost = 0
|
||||
# 모든 이모티콘에 대해 할인율과 할인 가격 계산
|
||||
for i in range(len(emoticons)):
|
||||
discount = config[i]
|
||||
# 사용자가 관심 있는 할인율만 구매 (예: discount >= min_discount)
|
||||
if discount >= min_discount:
|
||||
discounted_price = emoticons[i] * (100 - discount) // 100
|
||||
total_cost += discounted_price
|
||||
# 기준 가격에 따른 플러스 가입 여부 결정
|
||||
if total_cost >= price_threshold:
|
||||
plus_count += 1
|
||||
else:
|
||||
sales += total_cost
|
||||
|
||||
# 전역 결과 갱신 (가입자 우선, 매출액 두번째)
|
||||
if plus_count > max_plus or (plus_count == max_plus and sales > max_sales):
|
||||
max_plus = plus_count
|
||||
max_sales = sales
|
||||
|
||||
|
||||
|
||||
def solution(users_input, emoticons_input):
|
||||
global users, emoticons, max_plus, max_sales
|
||||
users = users_input
|
||||
emoticons = emoticons_input
|
||||
max_plus = 0
|
||||
max_sales = 0
|
||||
|
||||
poss_ratio = [40, 30, 20, 10]
|
||||
emoji_count = len(emoticons)
|
||||
|
||||
DFS(0, [], emoji_count, poss_ratio)
|
||||
|
||||
return [max_plus, max_sales]
|
||||
Reference in New Issue
Block a user