Advertisement
alexOloieri

Untitled

Nov 19th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define nmax 26
  3. using namespace std;
  4. long long cost[nmax], ans, sact, nw;
  5. map<long long,int>mp[nmax];
  6. string s;
  7. int main()
  8. {
  9.     for (int i=0;i<nmax;++i)
  10.         cin>>cost[i];
  11.     cin>>s;
  12.     for (int i=0;i<s.size();++i)
  13.     {
  14.         nw = s[i] - 'a';
  15.         ans += mp[nw][sact];
  16.         sact += cost[nw];
  17.         ++mp[nw][sact];
  18.     }
  19.     cout<<ans<<'\n';
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement