#abc268f. F - Best Concatenation
F - Best Concatenation
Score : points
问题描述
给定由数字 1
到 9
及字符 X
组成的 个字符串 。
我们将选择一个 的排列 来构建一个字符串 ,其中 $+$
表示字符串的连接操作。
然后,我们计算字符串 (其中 表示 的长度)的“得分”。
得分通过以下 步骤从初始分数 开始计算:
- 对于满足条件 ,
X
, 和1
的整数对 的数量,将 分加到得分上。 - 对于满足条件 ,
X
, 和2
的整数对 的数量,将 分加到得分上。 - 对于满足条件 ,
X
, 和3
的整数对 的数量,将 分加到得分上。 - 对于满足条件 ,
X
, 和9
的整数对 的数量,将 分加到得分上。
当 可以任意选择时,求 的最大可能得分。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given strings consisting of digits from 1
through 9
and the character X
.
We will choose a permutation of to construct a string , where denotes a concatenation of strings.
Then, we will calculate the "score" of the string (where denotes the length of ).
The score is calculated by the following steps, starting from the initial score :
- Add point to the score as many times as the number of integer pairs such that ,
X
, and1
. - Add points to the score as many times as the number of integer pairs such that ,
X
, and2
. - Add points to the score as many times as the number of integer pairs such that ,
X
, and3
. - Add points to the score as many times as the number of integer pairs such that ,
X
, and9
.
Find the maximum possible score of when can be chosen arbitrarily.
Constraints
- is an integer.
- is a string of length at least consisting of digits from
1
through9
and the characterX
. - The sum of lengths of is at most .
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
1X3
59
XXX
Sample Output 1
71
When , we have XXX1X359
. Then, the score of is calculated as follows:
- there are integer pairs such that ,
X
, and1
; - there are integer pairs such that ,
X
, and3
; - there are integer pairs such that ,
X
, and5
; - there are integer pairs such that ,
X
, and9
.
Therefore, the score of is $1 \times 3 + 3 \times 4 + 5 \times 4 + 9 \times 4 = 71$, which is the maximum possible value.
Sample Input 2
10
X63X395XX
X2XX3X22X
13
3716XXX6
45X
X6XX
9238
281X92
1XX4X4XX6
54X9X711X1
Sample Output 2
3010
update @ 2024/3/10 11:19:23