#P2178. [NOI2015] 品酒大会
[NOI2015] 品酒大会
Description
The annual "Phantom Pavilion Summer Wine Tasting Convention" has grandly opened. The convention consists of two parts: tasting and a fun challenge. They award two titles, "Chief Taster" and "Chief Hunter", attracting many sommeliers to participate.
At the dinner, the bartender Rainbow mixed cocktails. These cocktails are arranged in a line. The -th glass () is labeled , where each label is one of the lowercase English letters. Let denote the string formed by concatenating the labels from the -th glass to the -th glass in order. If , where , , , and , then we say the -th glass and the -th glass are r-similar. Of course, if two glasses are r-similar (with ), then they are also 1-similar, 2-similar, …, and -similar. In particular, for any , , the -th and the -th glasses are 0-similar.
In the tasting part, the sommelier Freda easily evaluated the deliciousness of each glass and won the title of "Chief Taster" with her professional skill and experience. The deliciousness of the -th glass () is . Now Rainbow announces the challenge: the cocktails in this convention have a special property—if you mix the -th glass with the -th glass, you obtain a glass with deliciousness . For each , please count how many ways there are to choose two r-similar glasses, and report the maximum deliciousness obtainable by mixing two r-similar glasses.
Input Format
The first line contains a positive integer , the number of glasses.
The second line contains a string of length , where the -th character is the label of the -th glass.
The third line contains integers separated by single spaces, where the -th integer is the deliciousness of the -th glass.
Output Format
Output lines.
On the -th line, output two integers separated by a single space. The first integer is the number of ways to choose two -similar glasses, and the second integer is the maximum deliciousness obtainable by mixing two -similar glasses. If there are no two -similar glasses, output .
10
ponoiiipoi
2 1 4 7 4 8 3 6 4 7
45 56
10 56
3 32
0 0
0 0
0 0
0 0
0 0
0 0
0 0
12
abaabaabaaba
1 -2 3 -4 5 -6 7 -8 9 -10 11 -12
66 120
34 120
15 55
12 40
9 27
7 16
5 7
3 -4
2 -4
1 -4
0 0
0 0
Hint
[Sample explanation 1]
Use an ordered pair to denote the -th glass and the -th glass.
0-similar: all ordered pairs are 0-similar, and the maximum deliciousness is .
1-similar: $(1, 8) (2, 4) (2, 9) (4, 9) (5, 6) (5, 7) (5, 10) (6, 7) (6, 10) (7, 10)$, with maximum .
2-similar: , with maximum .
There are no 3-, 4-, 5-, …, 9-similar pairs of glasses, so output .

[Time limit 1 s, Memory limit 500 MB]
Translated by ChatGPT 5
京公网安备 11011102002149号