Post

๐ŸฆŠ ์ด๋ชจํ‹ฐ์ฝ˜ ํ• ์ธ ํ–‰์‚ฌ

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.