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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from itertools import product

def solution(k, n, reqs):
    mentor = range(1, n + 1)
    mentors = [p for p in product(mentor, repeat=k) if sum(p) == n]
    
    min_wait_time = 10000000
    # ๋ฉ˜ํ†  ๋ฐฐ์น˜ํ•˜๋Š” ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜
    for mentor_case in mentors:
        # ์ƒ๋‹ด ๋Œ€๊ธฐํ
        wating_queue = []
        for i in range(k):
            wating_queue.append([])
        # n๋ฒˆ์งธ ์ผ€์ด์Šค ๊ฒ€์‚ฌ
        for i in range(len(mentor_case)):
            # i+1 ๋ฒˆ ๋ฉ˜ํ† ์˜ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„ ๊ณ„์‚ฐ
            mentor_index = i + 1
            mentor_count = mentor_case[i] # ๋ฉ˜ํ†  ์ˆ˜
            total_wait_time = 0
            for start, time, number in reqs:
                # ์ด ๋ฉ˜ํ† ์— ํ•ด๋‹นํ•˜๋Š” ์ƒ๋‹ด ์ผ€์ด์Šค๋ฉด
                if number == mentor_index:
                    # ์ƒ๋‹ด ํ ๊ฒ€์‚ฌ
                    # ์•„์ง ์‚ฌ๋žŒ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์œผ๋ฉด ์ €์žฅ
                    if len(wating_queue[i]) < mentor_count:
                        wating_queue[i].append([start, start + time])
                    # ์‚ฌ๋žŒ์„ ๋ชป๋ฐ›์œผ๋ฉด ์•ž์— ๊ฒƒ์„ ๋นผ๋‚ด๊ณ  ์‹œ๊ฐ„ ๊ฒ€์‚ฌ
                    else:
                        # ์ œ์ผ ๋นจ๋ฆฌ ๋๋‚˜๋Š” ์ˆœ์œผ๋กœ ์ €์žฅ
                        wating_queue[i] = sorted(wating_queue[i], key=lambda x: x[1])
                        started, end = wating_queue[i].pop(0)
                        # ์‹œ์ž‘ ์‹œ๊ฐ„์ด ์ œ์ผ ๋นจ๋ฆฌ ๋๋‚œ ์‚ฌ๋žŒ ๋ณด๋‹ค ๋Š๋ฆฌ๋ฉด ๊ธฐ๋‹ค๋ฆผ
                        # ๊ธฐ๋‹ค๋ ธ๋˜ ์‹œ๊ฐ„
                        if start < end:
                            wait_time = end - start
                            total_wait_time += wait_time
                            # ์ด์ „ ์‚ฌ๋žŒ์ด ๋๋‚œ ์งํ›„๋กœ ์ €์žฅ
                            wating_queue[i].append([end, end + time])
                        else:
                            wating_queue[i].append([start, start + time])
        min_wait_time = min(min_wait_time, total_wait_time)
    return min_wait_time
  • ์ •ํ™•์„ฑ


3. ํ•ด์„ค

์žฌ๋„์ „ ํ•„์š”

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