Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings
题意:
对于26个字母 每个字母分别有一个权值
给出一个字符串,找出有多少个满足条件的子串,
条件:1、第一个字母和最后一个相同,2、除了第一个和最后一个字母外,其他的权和为0
思路:
预处理出sum[i]:s[0~i]的和
开26个map<LL, LL>numV 分别表示 每个字母前缀和 的个数
例如处理到第i个元素,且numV[s[i]-'a'][sum[i]-v[s[i] - 'a']] (值为2)
表示在处理到的元素之前 以s[i]结尾的前缀和为sum[i]-v[s[i]-'a']的个数有2个
所以答案就要加2(因为前面已经组成过这个值,又出现的原因就是他的值变为了0)
const int maxv = ;
int v[maxv];
map<LL, LL> numV[maxv]; const int maxn = + ;
char s[maxn];
LL sum[maxn];
void init()
{
for (int i = ; i < ; i++)
{
scanf("%d", v + i);
}
scanf(" ");
gets(s);
} void solve()
{
int len = strlen(s);
sum[] = v[s[]-'a'];
for (int i = ; i < len; i++)
{
sum[i] = sum[i-] + v[s[i]-'a'];
} LL ans = ;
for (int i = ; i < len; i++)
{
ans += numV[s[i]-'a'][sum[i] - v[s[i] - 'a']];
numV[s[i]-'a'][sum[i]]++;
}
printf("%lld\n", ans);
} int main()
{
init();
solve();
return ;
}
Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings的更多相关文章
- Codeforces Round #294 (Div. 2)D - A and B and Interesting Substrings 字符串
D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megaby ...
- Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings [dp 前缀和 ]
传送门 D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 me ...
- Codeforces Round #294 (Div. 2)
水 A. A and B and Chess /* 水题 */ #include <cstdio> #include <algorithm> #include <iost ...
- Codeforces Round #294 (Div. 2)C - A and B and Team Training 水题
C. A and B and Team Training time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces Round #294 (Div. 2)B - A and B and Compilation Errors 水题
B. A and B and Compilation Errors time limit per test 2 seconds memory limit per test 256 megabytes ...
- Codeforces Round #294 (Div. 2)A - A and B and Chess 水题
A. A and B and Chess time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #294 (Div. 2) A and B and Lecture Rooms(LCA 倍增)
A and B and Lecture Rooms time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- Oracle存储过程例子:运用了正则表达式、数组等
代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-- ...
- linux下删除文件夹的命令
使用rm -rf 目录名字 命令即可 -r 就是向下递归,不管有多少级目录,一并删除-f 就是直接强行删除,不作任何提示的意思 eg 删除文件夹实例:rm -rf /var/log/httpd/acc ...
- boost和std中的thread的引用参数
boost 1.60.0 先上代码: #include <boost/thread.hpp> #include <iostream> void add(int &i) ...
- java.io.IOException: Cannot run program "jad"
今天调试google tag manager, 需要看看google analytics source code,无奈没有源码,装个一个插件ejad 还是不行: java.io.IOException ...
- logistc regression练习(三)
% Exercise 4 -- Logistic Regression clear all; close all; clc x = load('E:\workstation\data\ex4x.dat ...
- Counting Bits(Difficulty: Medium)
题目: Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate ...
- python基础之内置函数
该博客内容参考http://www.cnblogs.com/wupeiqi/articles/4943406.html 内置函数 一 详细见python文档,猛击这里 文件操作 操作文件时,一般需要经 ...
- AXUre
[ Javascript ] 一.javascript能用来干什么? 1.数据的验证. 2.对动态这本写到网页当中. 3.可以对事件做出响应. 4.可以读写html 中的内室. 5.可以检测浏览器 6 ...
- KinerCode.js
1 /*验证码*/ function KinerCode(options) { this.opt = this.extend(true, this.options, options); this.op ...
- Those who are not capable of Control their moods are not supposed to be ready for their baby.
I hate these Stupid Selfish People. We need Children Caring Organization.