CF910C.Minimum Sum
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Petya has n positive integers _a_1, _a_2, ..., a__n.
His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'.
Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros.
彼得有 n 个正整数 a1,a2,…,an。
他的朋友瓦夏开玩笑地将彼得所有数字中的每一位数字都替换成了字母。他使用了拉丁字母表中的小写字母 'a' 到 'j':将所有数字 0 替换为某个字母,所有数字 1 替换为另一个字母,依此类推。对于任意两个不同的数字,瓦夏均使用 'a' 到 'j' 中互不相同的字母。
你的任务是还原彼得的原始数字。还原后的数字应为不含前导零的正整数。由于可能存在多种还原方式,请确定所有可能还原方案中,彼得的这些数字之和的最小可能值。题目保证:在瓦夏恶作剧之前,彼得的所有数字均不含前导零。
输入格式
The first line contains a single integer n (1 ≤ n ≤ 1 000) — the number of Petya's numbers.
Each of the following lines contains non-empty string s__i consisting of lowercase Latin letters from 'a' to 'j' — the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters.
第一行包含一个整数 n(1≤n≤1000)—— 表示 Petya 的数字个数。
接下来的 n 行,每行包含一个非空字符串 si,该字符串仅由小写拉丁字母 'a' 到 'j' 组成 —— 这是 Vasya 开玩笑后 Petya 的数字。每个字符串的长度不超过六个字符。
输出格式
Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests.
确定恢复后所有Petya数字的最小总和。恢复后的数字应为不含前导零的正整数。对于所有给定的测试用例,保证存在一种正确的恢复方式(即不含前导零)。
输入输出样例
输入#1
3 ab de aj
输出#1
47
输入#2
5 abcdef ghij bdef accbd g
输出#2
136542
输入#3
3 aa jj aa
输出#3
44
说明/提示
In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration.
In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3].
In the second example the numbers after the restoration can look like: [11, 22, 11].
在第一个例子中,你需要将字母 'a' 替换为数字 1,字母 'b' 替换为数字 0,字母 'd' 替换为数字 2,字母 'e' 替换为数字 3,字母 'j' 替换为数字 4。因此恢复后的数字序列为 [10, 23, 14]。它们的和为 47,这是在正确恢复后所能得到的数字之和的最小值。
在第二个例子中,恢复后的数字序列可以是:[120468, 3579, 2468, 10024, 3]。
在第二个例子中,恢复后的数字序列也可以是:[11, 22, 11]。
输入解题思路,AI测评打分。不知道怎么写?