아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Clean Up!

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

요약
서로 다른 파일 이름들이 주어질 때, 각각 최대 k개씩만 선택하는 접두사 패턴으로 모든 파일을 덮는 최소 개수를 구한다.
난이도

보통10점 중 7점

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

문제

Once Charlie decided to start a new life by deleting all files in his Downloads directory. It's easy to do that using bash shell! It has two useful features: the "rm" command, which removes all files given as arguments, and patterns, which are replaced with the list of files matching them before executing the command.

Charlie ran "rm *", but received an "Argument list too long" response. Unfortunately, after bash replaced "*" with the names of all files in the Downloads directory, it failed to run the command because it had too many arguments.

After some experiments, Charlie realized he can execute "rm abc*" to delete all files with names starting with "abc" if there are at most kk such files. If more than kk files match this pattern, none of them will be deleted. Of course, he can replace "abc" with any string.

Help Charlie to find the smallest number of "rm" commands needed to delete all files. Assume that he can only use the "rm" command as "rm <prefix>*", where <prefix> consists of lowercase English letters (and can be empty).

입력

The first line contains two integers nn and kk --- the number of files to delete, and the maximum number of files that can be deleted by one "rm" command (1≤n,k≤3⋅1051 \le n, k \le 3 \cdot 10^5).

Each of the next nn lines contains a single string, denoting a file name. All file names are distinct, non-empty, and consist of lowercase English letters. The total length of all file names doesn't exceed 3⋅1053 \cdot 10^5.

출력

Print a single integer --- the smallest number of "rm" commands needed to delete all files.

힌트

In the first example test, Charlie can execute "rm ab*" to delete files "abc" and "abd", and then execute "rm *" to delete files "a" and "b". Note that he can't just run "rm *" immediately, because initially all four files match an empty prefix.

예제3

  1. 예제 1

    입력
    4 2
    a
    abc
    abd
    b
    
    예상 출력
    2
    
  2. 예제 2

    입력
    4 2
    d
    c
    ab
    a
    
    예상 출력
    2
    
  3. 예제 3

    입력
    5 3
    please
    remove
    all
    these
    files
    
    예상 출력
    3