NOI '15 P4 - Homeric Epics

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

In Homeric Epics there are n different words numbered from 1 to n. The i-th word appears wi times in the text. Allison wants to substitute the i-th word with a k-ary string si, satisfying the following constraint: for any 1i,jn, ij, si is not the prefix of sj.

Allison wants to know how to choose si so that the resulting text has minimum length. Under the assumption that the total length of the text is minimal, Allison wants to know what is the shortest possible length of the longest si.

A string is called a k-ary string if and only if its characters are in {0,1,,k1}.

A string s1 is said to be a prefix of s2 if and only if there exists 1tm such that s1=s2[1t] where m is the length of s2 and s2[1t] represents the substring of s2 formed by the first t characters.

Input Specification

The first line of the input file contains two integers n,k separated by one space, denoting there are n words in total and we need to substitute the words with a k-ary string.

In the following n lines, the (i+1)-th line has a nonnegative integer wi denoting the number of times the i-th word has occurred.

Output Specification

The output consists of two lines. The first line is an integer denoting the minimum length of the Homeric Epics after substitution. The second line is an integer denoting the minimum length of the longest string si given the total length is minimum.

Sample Input 1

Copy
4 2
1
1
2
2

Sample Output 1

Copy
12
2

Sample Input 2

Copy
6 3
1
1
3
3
9
9

Sample Output 2

Copy
36
3

Constraints

Test CasenkAdditional Constraintswi
1n=3k=20<wi1011
2n=5k=2
3n=16k=2All wi are equal.
4n=1000k=2The wi are generated uniformly at random.
5n=1000k=2
6n=100000k=2
7n=100000k=2All wi are equal.
8n=100000k=2
9n=7k=3
10n=16k=3All wi are equal.
11n=1001k=3All wi are equal.
12n=99999k=4All wi are equal.
13n=100000k=4
14n=100000k=4
15n=1000k=5
16n=100000k=7The wi are generated uniformly at random.
17n=100000k=7
18n=100000k=8The wi are generated uniformly at random.
19n=100000k=9
20n=100000k=9

Scoring

For each test case:

  • If only the first line is correct, 40% of points will be awarded;
  • If both lines are correct, 100% of points will be awarded.

Comments

There are no comments at the moment.