CF1327G.Letters and Question Marks

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a string SS and an array of strings [t1,t2,…,tk][t_1, t_2, \dots, t_k]. Each string tit_i consists of lowercase Latin letters from a to n; SS consists of lowercase Latin letters from a to n and no more than 1414 question marks.

Each string tit_i has its cost cic_i — an integer number. The value of some string TT is calculated as ∑i=1kF(T,ti)⋅ci\sum\limits_{i = 1}^{k} F(T, t_i) \cdot c_i, where F(T,ti)F(T, t_i) is the number of occurences of string tit_i in TT as a substring. For example, F(aaabaaa,aa)=4F(\text{aaabaaa}, \text{aa}) = 4.

You have to replace all question marks in SS with pairwise distinct lowercase Latin letters from a to n so the value of SS is maximum possible.

给你一个字符串 SS 和一个字符串数组 [t1,t2,…,tk][t_1, t_2, \dots, t_k]。每个字符串 tit_i 仅由小写拉丁字母 a 到 n 组成;字符串 SS 由小写拉丁字母 a 到 n 及至多 1414 个问号(?)组成。

每个字符串 tit_i 都有一个对应的成本 cic_i —— 一个整数。某个字符串 TT 的值定义为 ∑i=1kF(T,ti)⋅ci\sum\limits_{i = 1}^{k} F(T, t_i) \cdot c_i,其中 F(T,ti)F(T, t_i) 表示子串 tit_i 在 TT 中出现的次数(允许重叠)。例如,F(aaabaaa,aa)=4F(\text{aaabaaa}, \text{aa}) = 4。

你需要将 SS 中的所有问号替换为互不相同的、取自 a 到 n 的小写拉丁字母,使得 SS 的值尽可能大。

输入格式

The first line contains one integer kk (1≤k≤10001 \le k \le 1000) — the number of strings in the array [t1,t2,…,tk][t_1, t_2, \dots, t_k].

Then kk lines follow, each containing one string tit_i (consisting of lowercase Latin letters from a to n) and one integer cic_i (1≤∣ti∣≤10001 \le |t_i| \le 1000, −106≤ci≤106-10^6 \le c_i \le 10^6). The sum of lengths of all strings tit_i does not exceed 10001000.

The last line contains one string SS (1≤∣S∣≤4⋅1051 \le |S| \le 4 \cdot 10^5) consisting of lowercase Latin letters from a to n and question marks. The number of question marks in SS is not greater than 1414.

第一行包含一个整数 kk(1≤k≤10001 \le k \le 1000)—— 表示数组 [t1,t2,…,tk][t_1, t_2, \dots, t_k] 中字符串的个数。

接下来是 kk 行,每行包含一个字符串 tit_i(由小写拉丁字母 a 到 n 组成)和一个整数 cic_i(1≤∣ti∣≤10001 \le |t_i| \le 1000,−106≤ci≤106-10^6 \le c_i \le 10^6)。所有字符串 tit_i 的长度之和不超过 10001000。

最后一行包含一个字符串 SS(1≤∣S∣≤4⋅1051 \le |S| \le 4 \cdot 10^5),由小写拉丁字母 a 到 n 和问号组成。字符串 SS 中问号的个数不超过 1414。

输出格式

Print one integer — the maximum value of SS after replacing all question marks with pairwise distinct lowercase Latin letters from a to n.

输出一个整数——将所有问号替换为互不相同的、从 a 到 n 的小写拉丁字母后,SS 的最大可能值。

输入输出样例

  • 输入#1

    4
    abc -10
    a 1
    b 1
    c 3
    ?b?

    输出#1

    5
  • 输入#2

    2
    a 1
    a 1
    ?

    输出#2

    2
  • 输入#3

    3
    a 1
    b 3
    ab 4
    ab

    输出#3

    8
  • 输入#4

    1
    a -1
    ?????????????

    输出#4

    0
  • 输入#5

    1
    a -1
    ??????????????

    输出#5

    -1

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

首页