๐ฆ ์ด๋ชจํฐ์ฝ ํ ์ธ ํ์ฌ
1. ๋ฌธ์ ๋งํฌ
2. ์ฝ๋
์ ํ์ฑ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
์ฑ์ ์ ์์ํฉ๋๋ค. ์ ํ์ฑ ํ ์คํธ ํ ์คํธ 1 ใ ํต๊ณผ (0.07ms, 10.2MB) ํ ์คํธ 2 ใ ํต๊ณผ (0.10ms, 10.2MB) ํ ์คํธ 3 ใ ํต๊ณผ (0.39ms, 10.2MB) ํ ์คํธ 4 ใ ํต๊ณผ (3.17ms, 10.3MB) ํ ์คํธ 5 ใ ํต๊ณผ (5.96ms, 10.2MB) ํ ์คํธ 6 ใ ํต๊ณผ (3.18ms, 10.2MB) ํ ์คํธ 7 ใ ํต๊ณผ (15.44ms, 10.1MB) ํ ์คํธ 8 ใ ํต๊ณผ (15.90ms, 10.3MB) ํ ์คํธ 9 ใ ํต๊ณผ (81.36ms, 10.1MB) ํ ์คํธ 10 ใ ํต๊ณผ (41.33ms, 10.2MB) ํ ์คํธ 11 ใ ํต๊ณผ (338.91ms, 10.3MB) ํ ์คํธ 12 ใ ํต๊ณผ (174.74ms, 10.2MB) ํ ์คํธ 13 ใ ํต๊ณผ (1789.16ms, 10.3MB) ํ ์คํธ 14 ใ ํต๊ณผ (1652.36ms, 10.2MB) ํ ์คํธ 15 ใ ํต๊ณผ (107.04ms, 10.3MB) ํ ์คํธ 16 ใ ํต๊ณผ (96.70ms, 10.2MB) ํ ์คํธ 17 ใ ํต๊ณผ (0.42ms, 10.1MB) ํ ์คํธ 18 ใ ํต๊ณผ (29.93ms, 10.2MB) ํ ์คํธ 19 ใ ํต๊ณผ (0.06ms, 10.2MB) ํ ์คํธ 20 ใ ํต๊ณผ (0.06ms, 10.3MB) ์ฑ์ ๊ฒฐ๊ณผ ์ ํ์ฑ: 100.0 ํฉ๊ณ: 100.0 / 100.0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from itertools import product
def get_max(arr1, arr2):
count1, price1 = arr1
count2, price2 = arr2
if count1 == count2:
if price1 > price2:
return arr1
else:
return arr2
else:
if count1 > count2:
return arr1
else:
return arr2
def solution(users, emoticons):
answer = [0, 0]
sales = [10, 20, 30, 40]
# ํ ์ธ์จ์ ๋ํ ์ค๋ณต ์์ด ๊ตฌํจ
for sale in product(sales, repeat=len(emoticons)):
count = 0 # ์ด๋ชจํฐ์ฝ ํ๋ฌ์ค ๊ตฌ๋
์
price = 0 # ๋งค์ถ
emoticon_sale_price = []
for i in range(len(sale)):
emoticon_sale_price.append(int(emoticons[i] * (100 - sale[i]) / 100))
for to_percent, plus_price in users:
user_sum = 0
for i in range(len(sale)):
# ํน์ ์ธ์ผ๋ฅ ์ ๋์ผ๋ฉด
if sale[i] >= to_percent:
user_sum += emoticon_sale_price[i]
# ํน์ ๊ฐ๊ฒฉ์ ๋์ผ๋ฉด ์ด๋ชจํฐ์ฝ ํ๋ฌ์ค ๊ตฌ๋
if user_sum >= plus_price:
count += 1
# ๊ทธ๋ ์ง ์์ผ๋ฉด ๋งค์ถ๋ก
else:
price += user_sum
answer = get_max(answer, [count, price])
return answer
ํด์ค
ํ ์ธ์จ์ด 10, 20, 30, 40 ์ผ๋ก ๊ณ ์ ์ด๊ธฐ ๋๋ฌธ์ ์ค๋ณต ์์ด์ ํ์ฉ
๊ฐ ํ ์ธ์จ์ด ์ ์ฉ๋ ๊ฐ๊ฒฉ์ ๊ธฐ๋ฐ์ผ๋ก ์ํ
์ ์ ์ ํน์ ํ ์ธ์จ์ ๋ง์กฑ์ํจ ๊ฐ๊ฒฉ๋ง์ ๋ํ์ฌ ๊ธฐ์ค์ ์ถฉ์กฑํ๋ฉด ์ด๋ชจํฐ์ฝ ํ๋ฌ์ค ๊ตฌ๋
๊ทธ๋ ์ง ์์ผ๋ฉด ๋งค์ถ๋ก ๋ํจ
[count, price] ์ max ๊ฐ์ ๊ตฌํ๋ฉด ๋จ
This post is licensed under CC BY 4.0 by the author.