NOI '15 P5 - Cocktail Party

View as PDF

Submit solution

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

Problem types

You are given a string of length n representing the labels of n cups of cocktail. The i-th cup of cocktail has label si, and the labels are among the 26 lowercase English letters. Let Str(l,r)=slsl+1sr be the string formed by the labels of the cocktails from the l-th cup to the r-th cup. If Str(p,p0)=Str(q,q0) where 1pp0n, 1qq0n, pq, p0p+1=q0q+1=r, we say the p-th cup of cocktail and q-th cup of cocktail are r-similar. Of course, for two cups of cocktail that are r-similar (r>1) they are also 1-similar, 2-similar, ..., and (r1)-similar. In particular, for any 1pqn,pq, the p-th cup of cocktail and q-th cup of cocktail are 0-similar.

Freda assigns the "deliciousness" for each cup of cocktail, and the i-th cup has deliciousness ai. If we mix p-th cup of cocktail and q-th cup of cocktail, we may obtain cocktail with deliciousness apaq. The problem asks for each r=0,,n1, how many ways we may select two cups of cocktail that are r-similar, and compute the maximum possible deliciousness by mixing two cups of cocktail that are r-similar.

Input Specification

The first line of the input contains an integer n denoting the number of cups of cocktail. The second line contains a string S with length n such that the i-th character denotes the label of the i-th cup of cocktail. The third line contains n integers separated by a single space such that the i-th integer denotes the i-th cup of cocktail has deliciousness ai.

Output Specification

The output contains n lines. The i-th line contains two integers separated by a single space. The first integer denotes the number of ways to choose two cups of (i1)-similar cocktails. The second integer denotes the maximum possible deliciousness by mixing two cups of cocktails that are (i1)-similar. Notice if there does not exist two cups of cocktail that are (i1)-similar, both integers in that line of the output shall be 0.

Sample Input 1

Copy
10
ponoiiipoi
2 1 4 7 4 8 3 6 4 7

Sample Output 1

Copy
45 56
10 56
3 32
0 0
0 0
0 0
0 0
0 0
0 0
0 0

Sample Input 2

Copy
12
abaabaabaaba
1 -2 3 -4 5 -6 7 -8 9 -10 11 -12

Sample Output 2

Copy
66 120
34 120
15 55
12 40
9 27
7 16
5 7
3 -4
2 -4
1 -4
0 0
0 0

Constraints

Test CasenaiAdditional Constraints
1n=100|ai|10000
2n=200
3n=500
4n=750
5n=1000|ai|1000000000
6
7n=2000
8
9n=99991|ai|1000000000There will not exist 10-similar cocktails.
10
11n=100000|ai|1000000All ai are equal.
12n=200000
13n=300000
14
15n=100000|ai|1000000000
16
17n=200000
18
19n=300000
20

Comments

There are no comments at the moment.