CF519D.A and B and Interesting Substrings

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A and B are preparing themselves for programming contests.

After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.

A likes lowercase letters of the Latin alphabet. He has assigned to each letter a number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes).

B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one).

Also, A and B have a string s. Now they are trying to find out how many substrings t of a string s are interesting to B (that is, t starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero.

Naturally, A and B have quickly found the number of substrings t that are interesting to them. Can you do it?

A 和 B 正在为编程竞赛做准备。

在多年从事程序设计竞赛、解决大量需要计算各类抽象对象的问题之后,A 和 B 也形成了相当独特的偏好。

A 喜欢拉丁字母表中的小写字母。他为每个字母赋予了一个数值,表示他对该字母的喜爱程度(他对不喜欢的字母赋予了负数)。

B 喜欢子串。他尤其喜欢那些首尾字母相同(且长度严格大于一)的子串。

此外,A 和 B 共同拥有一个字符串 ss。现在他们试图找出字符串 ss 中有多少个子串 tt 同时满足以下两个条件:

  1. 对 B 来说是“有趣的”,即 tt 的首尾字母相同,且其长度大于一;
  2. 除去 tt 的首字母和尾字母后,其余所有字母(按 A 所赋的数值)之和恰好为零。

显然,A 和 B 很快就求出了满足上述条件的子串 tt 的数量。你也能做到吗?

输入格式

The first line contains 26 integers x__a, x__b, ..., x__z ( - 105 ≤ x__i ≤ 105) — the value assigned to letters a, b, c, ..., z respectively.

The second line contains string s of length between 1 and 105 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.

第一行包含 26 个整数 xa, xb, …, xzx_a,\,x_b,\,\dots,\,x_z(−105≤xi≤105-10^5 \le x_i \le 10^5),分别表示字母 a, b, c, …, za,\,b,\,c,\,\dots,\,z 对应的数值。

第二行包含一个长度在 11 到 10510^5 之间的字符串 ss,由小写拉丁字母组成——你需要为该字符串计算答案。

输出格式

Print the answer to the problem.

输出该问题的答案。

输入输出样例

  • 输入#1

    1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
    xabcab

    输出#1

    2
  • 输入#2

    1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
    aaa

    输出#2

    2

说明/提示

In the first sample test strings satisfying the condition above are abca and bcab.

In the second sample test strings satisfying the condition above are two occurences of aa.

在第一个样例测试中,满足上述条件的字符串是 abca 和 bcab。

在第二个样例测试中,满足上述条件的字符串是两个 aa。

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

首页