CF616F.Expensive Strings

省选/NOI-

通过率:0%

时间限制:6.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given n strings t__i. Each string has cost c__i.

Let's define the function of string , where p__s, i is the number of occurrences of s in t__i, |s| is the length of the string s. Find the maximal value of function f(s) over all strings.

Note that the string s is not necessarily some string from t.

给你 $ n $ 个字符串 $ t_i $,每个字符串 $ t_i $ 有一个代价 $ c_i $。

定义字符串 $ s $ 的函数
,
其中 $ p_{s,i} $ 表示字符串 $ s $ 在 $ t_i $ 中的出现次数,$ |s| $ 表示字符串 $ s $ 的长度。求函数 $ f(s) $ 在所有可能字符串 $ s $ 上的最大值。

注意:字符串 $ s $ 不一定出现在给定的 $ t_i $ 中。

输入格式

The first line contains the only integer n (1 ≤ n ≤ 105) — the number of strings in t.

Each of the next n lines contains contains a non-empty string t__i. t__i contains only lowercase English letters.

It is guaranteed that the sum of lengths of all strings in t is not greater than 5·105.

The last line contains n integers c__i ( - 107 ≤ c__i ≤ 107) — the cost of the i-th string.

第一行包含唯一一个整数 nn(1≤n≤1051 \leq n \leq 10^5)——即字符串集合 tt 中字符串的个数。

接下来的 nn 行,每行包含一个非空字符串 tit_i。每个 tit_i 仅由小写英文字母组成。

保证 tt 中所有字符串的长度之和不超过 5⋅1055 \cdot 10^5。

最后一行包含 nn 个整数 cic_i(−107≤ci≤107-10^7 \leq c_i \leq 10^7)——表示第 ii 个字符串的代价。

输出格式

Print the only integer a — the maximal value of the function f(s) over all strings s. Note one more time that the string s is not necessarily from t.

输出唯一的整数 aa —— 函数 f(s)f(s) 在所有字符串 ss 上的最大值。请注意,字符串 ss 不一定来自 tt。

输入输出样例

  • 输入#1

    2
    aa
    bb
    2 1

    输出#1

    4
  • 输入#2

    2
    aa
    ab
    2 1

    输出#2

    5

输入解题思路,AI测评打分。不知道怎么写?

首页