Advertisement
Guest User

Untitled

a guest
Jul 27th, 2013
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <cstdio>
  7. #include <string>
  8. #include <vector>
  9. #include <queue>
  10. #include <deque>
  11. #include <cmath>
  12. #include <stack>
  13. #include <list>
  14. #include <set>
  15. #include <string.h>
  16. #include <map>
  17.  
  18. using namespace std;
  19.  
  20. typedef long long ll;
  21.  
  22. #define pii pair<int,int>
  23. #define mp make_pair
  24. #define f first
  25. #define s second
  26. #define BASE 256
  27. #define MOD 34027797218763967LL
  28. #define MAXN 1509
  29.  
  30. set<ll>ok;
  31. int k;
  32. bool bad[26];
  33. char s[MAXN];
  34. string ab;
  35.  
  36.  
  37. void Read() {
  38. scanf("%s",s);
  39. cin>>ab;
  40. scanf("%d",&k);
  41.  
  42. for (int i=0;i<26;i++)
  43. if (ab[i]=='0')
  44. bad[i]=true;
  45. }
  46.  
  47. void Solve() {
  48.  
  49. // hashing
  50. int len=strlen(s);
  51.  
  52. for (int i=0;i<len;i++) {
  53. int currbad=0;
  54. ll hash=0;
  55.  
  56. for (int j=i;j<len;j++) {
  57. hash=(hash*BASE +s[j])%MOD;
  58. if (bad[s[j]-97])
  59. currbad++;
  60. if (currbad<=k) {
  61. ok.insert(hash);
  62. }
  63. }
  64. }
  65.  
  66. printf("%d\n",ok.size());
  67. }
  68.  
  69.  
  70.  
  71. int main () {
  72. //freopen("cf.in","r",stdin);
  73. //freopen("cf.out","w",stdout);
  74.  
  75. Read();
  76. Solve();
  77.  
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement