Guest User

Untitled

a guest
Dec 14th, 2019
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. long long n,k;
  8. string s1;
  9. cin >> n>>k;
  10.  
  11. cin >> s1;
  12. string s2;
  13. getchar();
  14. getline(cin,s2);
  15. map<char,int>mp;
  16. if (k==26)
  17. {
  18. long long p1=n*(n+1);
  19. cout << p1/2 <<endl;
  20. }
  21.  
  22. else
  23. {
  24. for (int i=0; i<s2.size(); i++)
  25. {
  26. mp[s2[i]]=1;
  27. }
  28. int cnt=0;
  29. long long ans=0;
  30. for (int i=0; i<s1.size(); i++)
  31. {
  32. if (mp[s1[i]]==1)
  33. {
  34. cnt++;
  35. }
  36. if (mp[s1[i]]==0 || i==(s1.size()-1))
  37. {
  38. long long p1=cnt*(cnt+1);
  39. ans+=(p1/2);
  40. cnt=0;
  41. }
  42. }
  43. cout <<ans <<endl;
  44. }
  45.  
  46.  
  47.  
  48.  
  49.  
  50. return 0;
  51. }
RAW Paste Data