Codeforces Round #294 (Div. 2)-D. A and B and Interesting Substrings
来源:互联网 发布:孤岛惊魂3 优化 编辑:程序博客网 时间:2024/06/06 08:44
原题链接
遍历字符串的每一个位置,计算前缀和.定义map<ll, int> m[26], m[i][j]表示以字符'a'+i为结尾的字符串的前缀和为j的情况有多少个.
遍历每一个字符str[i], 计算前缀和为sum, 那么以str[i]为结尾的满足条件的字符串个数为m[str[i]-'a'][sum-该字符的number]
#include <bits/stdc++.h>#define maxn 100005using namespace std;typedef long long ll;char str[maxn];int num[30];map<ll, int> m[26];int main(){//freopen("in.txt", "r", stdin);for(int i = 0; i < 26; i++) scanf("%d", num+i);scanf("%s", str);ll sum = 0, ans = 0;for(int i = 0; str[i]; i++){ans += m[str[i]-'a'][sum];sum += num[str[i]-'a'];m[str[i]-'a'][sum]++;}printf("%I64d\n", ans);return 0;}
0 0
- Codeforces Round #294 (Div. 2)D. A and B and Interesting Substrings
- hash(Codeforces Round #294 (Div. 2)D. A and B and Interesting Substrings)
- Codeforces Round #294 (Div. 2) -- D. A and B and Interesting Substrings
- Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings
- Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings(map)
- 【codeforces】Round #294 (Div. 2) D. A and B and Interesting Substrings
- Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings(前缀和+map)
- Codeforces Round #294 (Div. 2) D题:A and B and Interesting Substrings
- Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings
- Codeforces Round #294 (Div. 2)-D. A and B and Interesting Substrings
- Codeforces 519D - A and B and Interesting Substrings (思维)
- Codeforces 519D A and B and Interesting Substrings
- A and B and Interesting Substrings - CodeForces 519 D dp
- CodeForces 519D A and B and Interesting Substrings
- codeforces A and B and Interesting Substrings
- CF(#294 div2):D. A and B and Interesting Substrings
- #294 (div.2) D.A and B and Interesting Substring
- codeforces 519D D. A and B and Interesting Substrings(hash+dp)
- HDU Mr. Frog’s Problem 2016CCPC东北地区大学生程序设计竞赛 - 重现赛
- python 类与实例
- tomcat-异常汇总
- javascript笔记
- [2016CCPC东北地区大学生程序设计竞赛] Minimum’s Revenge 贪心+水题
- Codeforces Round #294 (Div. 2)-D. A and B and Interesting Substrings
- ag grid
- SQL 之 集合逻辑
- 如何Windows创建OpenOffice服务
- 首发丨360开源的类Redis存储系统:Pika SSDB
- Hashtable与HashMap的区别?
- CSS选择器
- NOIP2010关押罪犯
- sql 基础知识