Post

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

1. ๋ฌธ์ œ ๋งํฌ

2023 KAKAO BLIND RECRUITMENT: ์ด๋ชจํ‹ฐ์ฝ˜ ํ• ์ธ ํ–‰์‚ฌ


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
26
27
28
29
30
31
32
33
from itertools import product

def solution(users, emoticons):
    answer = [0, 0]
    u_num = len(users)
    e_num = len(emoticons)
    discount_rate = [40, 30, 20, 10]
    # ์ด๋ชจํ‹ฐ์ฝ˜ ๊ฐœ์ˆ˜๋งŒํผ ๋ฝ‘๋Š” ๋ชจ๋“  ์ค‘๋ณต ์ˆœ์—ด ๊ตฌํ•˜๊ธฐ(์ด๋ชจํ‹ฐ์ฝ˜ ํ• ์ธ์œจ ๋ชจ๋“  ๊ฒฝ์šฐ ๊ตฌํ•˜๊ธฐ)
    for d_list in product(discount_rate, repeat=e_num):
        purchase_history = [0] * u_num
        now = [0, 0]    # ํ”Œ๋Ÿฌ์Šค ๊ฐ€์ž…์ž, ํŒ๋งค์•ก
        for i, d in enumerate(d_list):
            for j in range(u_num):
                # ์œ ์ €๊ฐ€ ์›ํ•œ ํ• ์ธ์œจ๋ณด๋‹ค ๋†’์œผ๋ฉด(๊ตฌ๋งค ์กฐ๊ฑด ์ถฉ์กฑ)
                if users[j][0] <= d:
                    purchase_history[j] += emoticons[i] * (100 - d) // 100
        # ์ด๋ชจํ‹ฐ์ฝ˜ ํ”Œ๋Ÿฌ์Šค ๊ฐ€์ž…์ž ํ™•์ธ
        for i in range(u_num):
            # ์ด๋ชจํ‹ฐ์ฝ˜ ๊ตฌ๋งค ๋น„์šฉ์ด ๋ณธ์ธ ์ผ์ • ๊ฐ€๊ฒฉ ์ด์ƒ -> ์ด๋ชจํ‹ฐ์ฝ˜ ํ”Œ๋Ÿฌ์Šค ๊ฐ€์ž…
            if users[i][1] <= purchase_history[i]:
                now[0] += 1
            # ํ”Œ๋Ÿฌ์Šค ๊ฐ€์ž…์ž ์•„๋‹๋•Œ -> ํŒ๋งค์•ก ์‚ฐ์ •
            else:
                now[1] += purchase_history[i]
        # 1์ˆœ์œ„: ์ด๋ชจํ‹ฐ์ฝ˜ ํ”Œ๋Ÿฌ์Šค ๊ฐ€์ž…์ž
        if answer[0] < now[0]:
            answer = now
        # 2์ˆœ์œ„: ํŒ๋งค์•ก
        elif answer[0] == now[0] and answer[1] < now[1]:
            answer = now
    
    return answer

  • ์ •ํ™•์„ฑ

    ํ…Œ์ŠคํŠธ 1 ใ€‰ํ†ต๊ณผ (0.05ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 2 ใ€‰ํ†ต๊ณผ (0.10ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 3 ใ€‰ํ†ต๊ณผ (0.45ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 4 ใ€‰ํ†ต๊ณผ (2.02ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 5 ใ€‰ํ†ต๊ณผ (3.68ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 6 ใ€‰ํ†ต๊ณผ (2.38ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 7 ใ€‰ํ†ต๊ณผ (20.09ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 8 ใ€‰ํ†ต๊ณผ (10.82ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 9 ใ€‰ํ†ต๊ณผ (91.58ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 10 ใ€‰ํ†ต๊ณผ (50.08ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 11 ใ€‰ํ†ต๊ณผ (451.38ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 12 ใ€‰ํ†ต๊ณผ (251.42ms, 10.4MB)
    ํ…Œ์ŠคํŠธ 13 ใ€‰ํ†ต๊ณผ (1973.12ms, 10.4MB)
    ํ…Œ์ŠคํŠธ 14 ใ€‰ํ†ต๊ณผ (1805.55ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 15 ใ€‰ํ†ต๊ณผ (87.65ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 16 ใ€‰ํ†ต๊ณผ (85.70ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 17 ใ€‰ํ†ต๊ณผ (0.44ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 18 ใ€‰ํ†ต๊ณผ (29.05ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 19 ใ€‰ํ†ต๊ณผ (0.09ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 20 ใ€‰ํ†ต๊ณผ (0.06ms, 10.2MB)


3. ํ•ด์„ค

์ด๋ชจํ‹ฐ์ฝ˜์— ๋ชจ๋“  ํ• ์ธ์œจ์„ ๋ถ€์—ฌํ•˜์—ฌ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๋”ฐ์ ธ ๊ฐ€์žฅ ์ตœ์„ ์˜ ์„ ํƒ์„ ๋ฝ‘๋Š”๋‹ค.

์ค‘๋ณต์ˆœ์—ด์„ ํ†ตํ•ด ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ํ• ์ธ์˜ ๊ฒฝ์šฐ๋ฅผ ๊ณ„์‚ฐํ•˜๊ณ  ๊ทธ๋•Œ์˜ ๋ชจ๋“  ๊ฒฐ๊ณผ(ํ”Œ๋Ÿฌ์Šค ๊ฐ€์ž…์ž, ํŒ๋งค์•ก)์„ ๋น„๊ตํ•ด์ค€๋‹ค.

์ด๋•Œ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ๋Œ€๋žต ๊ณ„์‚ฐํ•ด๋ดค์„ ๋•Œ ์ตœ์•…์˜ ๊ฒฝ์šฐ ์ด๋ชจํ‹ฐ์ฝ˜ ๊ฐœ์ˆ˜ = 7, ์œ ์ € ์ˆ˜ = 100์ด๊ณ , ์ด๋ชจํ‹ฐ์ฝ˜ ํ• ์ธ์œจ 4๊ฐœ๋กœ ๊ณ„์‚ฐ์„ ํ–ˆ์„ ๋•Œ ๋ชจ๋“  ๊ฒฝ์šฐ๋ฅผ ๊ตฌํ•˜๋Š” ์‹œ๊ฐ„์€ ์•„๋ž˜์™€ ๊ฐ™๊ณ , ๋ชจ๋“  ๊ฒฝ์šฐ๋ฅผ ๋‹ค ๊ตฌํ•ด๋„ 1์ดˆ์— 1์–ต๋ฒˆ ๊ณ„์‚ฐ์ด ๊ฐ€๋Šฅํ•˜๋‹ค๊ณ  ํ•œ๋‹ค๋ฉด ์ด 1์–ต๋ฒˆ ์ดํ•˜์ด๋ฏ€๋กœ ๋ชจ๋“  ๊ฒฝ์šฐ๋ฅผ ํƒ์ƒ‰ํ•ด๋„ ๋œ๋‹ค.

\[4^7 * 100 = 2^{14} * 10^2 = 2^{10} * 2^4 * 10^2 \fallingdotseq 10^3 * 16 * 10^2 = 1.6 * 10^6\]

์œ ์ €๋ณ„ ์ตœ์ข… ๊ตฌ๋งค๋‚ด์—ญ์„ ๊ตฌํ•œ ํ›„ ์ผ์ • ๊ฐ€๊ฒฉ ์ด์ƒ์€ ํ”Œ๋Ÿฌ์Šค ๊ฐ€์ž…์ž์— ๋”ํ•ด์ฃผ๊ณ , ์•„๋‹Œ ๊ฒฝ์šฐ ํŒ๋งค์•ก์— ๋”ํ•œ ํ›„ ์ตœ์ข… ๊ฐ’์„ max๊ฐ’๊ณผ ๋น„๊ตํ•˜์—ฌ ๋ณ€๊ฒฝํ•ด์ค€๋‹ค.

This post is licensed under CC BY 4.0 by the author.