#abc264g. G - String Fair
G - String Fair
Score : points
问题描述
在一场字符串展览中,他们确定一个非空的、由小写英文字母组成的字符串 的“美感”。
字符串 的美感等于由 个标准决定的 个评分之和。对于 ,第 个标准决定的评分是:“作为连续子序列在 中出现的次数”的 (输入中给出的长度 最多为3 的字符串)乘以 。
打印由小写英文字母组成的 非空 字符串 可能达到的最大美感。如果可以获得无限大的美感,则打印 Infinity
。
这里,字符串 作为连续子序列在字符串 中出现的次数定义为满足条件 且 的整数 的数量。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
In a string fair, they determine the beauty of a non-empty string consisting of lowercase English letters.
The beauty of string equals the sum of scores determined by criteria. For , the score determined by the -th criterion is "the number of occurrences of a string (of length at most given in the Input) in as a consecutive subsequence" multiplied by .
Print the maximum possible beauty of a non-empty string consisting of lowercase English letters. If it is possible to obtain infinitely large beauty, print Infinity
instead.
Here, the number of occurrences of a string in a string as a consecutive subsequence is defined to be the number of integers such that and .
Constraints
- is an integer.
- is a string of length between and consisting of lowercase English letters.
- is an integer.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible beauty of a non-empty string consisting of lowercase English letters. If it is possible to obtain infinitely large beauty, print Infinity
instead.
Sample Input 1
3
a -5
ab 10
ba -20
Sample Output 1
Infinity
For example, if abzabz
:
- The score determined by the -st criterion is points, because
a
occurs twice in as a consecutive subsequence. - The score determined by the -nd criterion is points, because
ab
occurs twice in as a consecutive subsequence. - The score determined by the -rd criterion is points, because
ba
occurs times in as a consecutive subsequence.
Thus, the beauty of is .
As another example, if abzabzabz
:
- The score determined by the -st criterion is points, because
a
occurs times in as a consecutive subsequence. - The score determined by the -nd criterion is points, because
ab
occurs times in as a consecutive subsequence. - The score determined by the -rd criterion is points, because
ba
occurs times in as a consecutive subsequence.
Thus, the beauty of is .
In general, for a positive integer , if is a concatenation of copies of abz
, then the beauty of is . Since you can obtain as large beauty as you want, Infinity
should be printed.
Sample Input 2
28
a -5
ab 10
ba -20
bb -20
bc -20
bd -20
be -20
bf -20
bg -20
bh -20
bi -20
bj -20
bk -20
bl -20
bm -20
bn -20
bo -20
bp -20
bq -20
br -20
bs -20
bt -20
bu -20
bv -20
bw -20
bx -20
by -20
bz -20
Sample Output 2
5
ab
achieves the maximum beauty possible.
Sample Input 3
26
a -1
b -1
c -1
d -1
e -1
f -1
g -1
h -1
i -1
j -1
k -1
l -1
m -1
n -1
o -1
p -1
q -1
r -1
s -1
t -1
u -1
v -1
w -1
x -1
y -1
z -1
Sample Output 3
-1
Note that should be a non-empty string.
update @ 2024/3/10 11:10:31