Advertisement
pdpd123

Problem 15

Feb 17th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.     cin.tie(0);
  5.     ios_base::sync_with_stdio(false);
  6.     string s;
  7.     int len,k;
  8.     char a[26];
  9.     cin >> len >> k;
  10.     cin >> s;
  11.     for(int i=0;i<k;i++) cin >> a[i];
  12.     for(int i=0;i<len;i++){
  13.         for(int j=0;j<k;j++){
  14.             if(s[i]==a[j]){
  15.                 break;
  16.             }
  17.             if(j==k-1 && s[i]!=a[j]) s[i]='0';
  18.         }
  19.     }
  20.     unsigned long long int count=0,max=0;
  21.     for(int i=0;i<len;i++){
  22.         if(s[i]!='0') max++;
  23.         else{
  24.             count+=(1+max)*max/2;
  25.             max=0;
  26.         }
  27.         if(i==len-1 && max) count+=(1+max)*max/2;
  28.     }
  29.     cout << count << endl;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement