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
def solution(cap, n, deliveries, pickups):
    answer = 0
    
    # ๋ฐฐ์—ด์ด ๋ชจ๋‘ 0์ธ ๊ฒฝ์šฐ
    zero_list = [0] * n
    if deliveries == pickups == zero_list:
        return answer
    
    while deliveries or pickups:
        answer += max(len(deliveries), len(pickups))
        d_limit, p_limit = cap, cap
        while deliveries:
            # ๋ฐฐ๋‹ฌ ๊ฐ€๋Šฅ, ๋ฐฐ๋‹ฌ ๋ถˆํ•„์š” ์ง‘
            if deliveries[-1] <= d_limit:
                d_limit -= deliveries.pop()
            # ๋ถ€๋ถ„ ๋ฐฐ๋‹ฌ
            else:
                deliveries[-1] -= d_limit
                break
        while pickups:
            # ํ”ฝ์—… ๊ฐ€๋Šฅ, ํ”ฝ์—… ๋ถˆํ•„์š” ์ง‘
            if pickups[-1] <= p_limit:
                p_limit -= pickups.pop()
            # ๋ถ€๋ถ„ ํ”ฝ์—…
            else:
                pickups[-1] -= p_limit
                break
            
    return answer * 2

  • ์ •ํ™•์„ฑ

    ํ…Œ์ŠคํŠธ 1 ใ€‰ํ†ต๊ณผ (0.01ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 2 ใ€‰ํ†ต๊ณผ (0.00ms, 10.1MB)
    ํ…Œ์ŠคํŠธ 3 ใ€‰ํ†ต๊ณผ (0.02ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 4 ใ€‰ํ†ต๊ณผ (0.01ms, 10.1MB)
    ํ…Œ์ŠคํŠธ 5 ใ€‰ํ†ต๊ณผ (0.03ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 6 ใ€‰ํ†ต๊ณผ (0.02ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 7 ใ€‰ํ†ต๊ณผ (0.46ms, 10.2MB)
    ํ…Œ์ŠคํŠธ 8 ใ€‰ํ†ต๊ณผ (1.24ms, 10.4MB)
    ํ…Œ์ŠคํŠธ 9 ใ€‰ํ†ต๊ณผ (5.51ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 10 ใ€‰ํ†ต๊ณผ (4.17ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 11 ใ€‰ํ†ต๊ณผ (3.61ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 12 ใ€‰ํ†ต๊ณผ (2.89ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 13 ใ€‰ํ†ต๊ณผ (1.15ms, 10.3MB)
    ํ…Œ์ŠคํŠธ 14 ใ€‰ํ†ต๊ณผ (1.31ms, 10.1MB)
    ํ…Œ์ŠคํŠธ 15 ใ€‰ํ†ต๊ณผ (21.60ms, 12.1MB)
    ํ…Œ์ŠคํŠธ 16 ใ€‰ํ†ต๊ณผ (1288.20ms, 12.1MB)
    ํ…Œ์ŠคํŠธ 17 ใ€‰ํ†ต๊ณผ (102.19ms, 12.2MB)
    ํ…Œ์ŠคํŠธ 18 ใ€‰ํ†ต๊ณผ (45.73ms, 12.1MB)
    ํ…Œ์ŠคํŠธ 19 ใ€‰ํ†ต๊ณผ (38.29ms, 12.2MB)
    ํ…Œ์ŠคํŠธ 20 ใ€‰ํ†ต๊ณผ (39.27ms, 12 MB)


3. ํ•ด์„ค

๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ๋‹ค.

๊ฐ€์žฅ ๋ฉ€๋ฆฌ ์žˆ๋Š” ์ง‘๋ถ€ํ„ฐ ํŠธ๋Ÿญ ์šฉ๋Ÿ‰๋งŒํผ ๋ฐฐ๋‹ฌ๊ณผ ํ”ฝ์—…์„ ์ง„ํ–‰ํ•œ๋‹ค. ๋ฐฐ๋‹ฌ ํ˜น์€ ํ”ฝ์—…์ด ๋‹ค ์™„๋ฃŒ๋œ ์ง‘์€ ์Šคํƒ์—์„œ ์ œ๊ฑฐํ•ด๋ฒ„๋ฆฐ๋‹ค.

์Šคํƒ์˜ ๊ธธ์ด๊ฐ€ ๋ฐฉ๋ฌธํ•ด์•ผํ•˜๋Š” ๊ฐ€์žฅ ๋จผ ๊ธธ์ด์ด๋ฏ€๋กœ ๋ฐฐ๋‹ฌ๊ณผ ํ”ฝ์—… ์ค‘ ๋” ํฐ ๊ฐ’์„ ๋”ํ•ด์ค€๋‹ค. (๋‘˜์€ ๋™์‹œ์— ์ด๋ฃจ์–ด์ง€๋ฏ€๋กœ)

๋งˆ์ง€๋ง‰์œผ๋กœ ์™•๋ณต์„ ๊ณ„์‚ฐํ•ด์•ผํ•˜๋ฏ€๋กœ answer์— 2๋ฅผ ๊ณฑํ•ด์ค€๋‹ค.

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