Cowdependence

시간 제한2초메모리 제한2048 MB

요약
각 그룹이 같은 라벨로만 이루어지고 최대 x마리 범위 안에 있어야 할 때, x = 1..N 각각에 대해 최소 그룹 수를 구한다.
난이도

어려움10점 중 8점

유형
그리디, 동적 계획법, 이분 탐색
정답자
아직 제출이 없습니다

문제

Farmer John's NN (1≤N≤105)(1 \leq N \leq 10^5) cows have been arranged into a line. The iith cow has label a_ia\_i (1≤a_i≤N1 \leq a\_i \leq N). A group of cows can form a friendship group if they all have the same label and each cow is within xx cows of all the others in the group, where xx is an integer in the range \[1,N]\[1,N]. Every cow must be in exactly one friendship group.

For each xx from 11 to NN, calculate the minimum number of friendship groups that could have formed.

입력

The first line consists of an integer NN.

The next line contains a_1...a_Na\_1 ... a\_N, the labels of each cow.

출력

For each xx from 11 to NN, output the minimum number of friendship groups for that xx on a new line.

힌트

Here are examples of how to assign cows to friendship groups for x=1x=1 and x=2x=2 in a way that minimizes the number of groups. Each letter corresponds to a different group.

Example:

       1 1 1 9 2 1 2 1 1
x = 1: A B B C D E F G G (7 groups)
x = 1: A A B C D E F G G (7 groups, alternative grouping)
x = 2: A A A B C D C E E (5 groups)
x = 2: A A A B C D C D E (5 groups, alternative grouping)

예제1

  1. 예제 1

    입력
    9
    1 1 1 9 2 1 2 1 1
    
    예상 출력
    7
    5
    4
    4
    4
    4
    4
    3
    3