Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define MOD 1000000007
- #define MOD1 1000000009
- #define PR 43
- #define PR1 37
- #define ll long long
- int mod_mul(long long a,long long b,int md)
- {
- return (a*b)%md;
- }
- int mod_plus(int a,int b,int md)
- {
- return (a+b)%md;
- }
- string str,arr;
- set<pair<int,int> >s;
- int main()
- {
- //freopen("input.txt","r",stdin);
- int i,j,k,t,a;
- int xx,pw,pw1,xx1;
- cin>>str>>arr>>k;
- for(i=0;i<str.size();i++){
- t=0;
- xx=0;
- pw=1;
- pw1=1;
- xx1=0;
- for(j=i,a=0;j<str.size();j++,a++){
- if(arr[str[j]-'a']=='0')t++;
- if(t>k)break;
- xx=mod_plus(xx,mod_mul(pw,str[j],MOD),MOD);
- xx1=mod_plus(xx1,mod_mul(pw1,str[j],MOD1),MOD1);
- s.insert(make_pair(xx,xx1));
- pw=mod_mul(pw,PR,MOD);
- pw1=mod_mul(pw1,PR1,MOD1);
- }
- }
- cout<<s.size()<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement