Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- cin.tie(0);
- ios_base::sync_with_stdio(false);
- string s;
- int len,k;
- char a[26];
- cin >> len >> k;
- cin >> s;
- for(int i=0;i<k;i++) cin >> a[i];
- for(int i=0;i<len;i++){
- for(int j=0;j<k;j++){
- if(s[i]==a[j]){
- break;
- }
- if(j==k-1 && s[i]!=a[j]) s[i]='0';
- }
- }
- unsigned long long int count=0,max=0;
- for(int i=0;i<len;i++){
- if(s[i]!='0') max++;
- else{
- count+=(1+max)*max/2;
- max=0;
- }
- if(i==len-1 && max) count+=(1+max)*max/2;
- }
- cout << count << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement