1508 레이스

정민용·2024년 3월 21일
0

백준

목록 보기
274/286

import sys

n, m, k = map(int, sys.stdin.readline().split())
pos = list(map(int, sys.stdin.readline().split()))

start, end = 1, n
res = ""
while start <= end:
    mid = (start + end) // 2
    check = False

    for i in range(k):
        l, people = i, 1
        my_pos = '0' * i + '1'
        for j in range(i+1, k):
            # 인접한 두 지점 거리가 mid 이상이라면 심판 배치
            if pos[j] - pos[l] >= mid:
                people += 1
                l = j
                my_pos += '1'
            else:
                my_pos += '0'

            # m명의 심판을 모두 배치하면 나머지는 다 빈공간
            if people == m:
                for _ in range(j+1, k):
                    my_pos += '0'
                break

        if people == m:
            res = my_pos
            check = True
            break

    if check:
        start = mid + 1
    else:
        end = mid - 1

sys.stdout.write(res)

1508 레이스

0개의 댓글