-
Notifications
You must be signed in to change notification settings - Fork 0
/
271D.cpp
137 lines (117 loc) · 2.23 KB
/
271D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <stack>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#include <stdio.h>
#define MOD 100000000
#define exit return 0
#define inf 10000000000
#define exit return 0
#define PS system("pause")
#define S 100007
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left (v<<1)
#define right (left|1)
#define mid ((tl+tr)>>1)
#define SZ(x) ((int)x.size())
#define MX(a,b)a>b?a:b
const double eps = 1e-10;
using namespace std;
#define ll long long
//using ul = unsigned long long;
using PII = pair<int, int>;
const long NN = (1 << 18);
int answww;
int n, m, q, d, c;
int x, y;
int zzz;
struct Trie{
char c;
bool is;
Trie* child[26];
Trie(){
c = 0;
is = false;
for (int i = 0; i < 26; i++){
child[i] = NULL;
}
}
Trie(char _c){
c = _c;
is = false;
for (int i = 0; i < 26; i++){
child[i] = NULL;
}
}
void addEdge(char pp){
if (child[pp - 'a'] == NULL){
child[pp - 'a'] = new Trie(pp);
}
}
Trie* get(char _c){
return child[_c - 'a'];
}
};
Trie rr;
int ans;
Trie* addW(Trie *on, string &s, int xx){
if (xx == s.length())return on;
on->addEdge(s[xx]);
return addW((on->get(s[xx])), s, xx + 1);
}
Trie *getW(Trie *on, string &s, int xx){
if (xx == s.length()){
if (!(on->is)){
on->is = true;
ans++;
}
return on;
}
return getW(on->get(s[xx]), s, xx + 1);
}
int main(){
string ss, bt;
cin >> ss >> bt;
scanf("%d", &c);
for (int i = 0; i < ss.length(); i++){
string save = "";
Trie *vv = &rr;
for (int j = i; j < ss.length(); j++){
save += ss[j];
vv = addW(vv, save, j - i);
}
}
for (int i = 0; i < ss.length(); i++){
string was = "";
Trie *vv = &rr;
int bads = 0;
for (int j = i; j < ss.length(); j++){
was += ss[j];
if (bt[ss[j] - 'a'] == '0')bads++;
if (bads>c)break;
vv = getW(vv, was, j - i);
}
}
printf("%d", ans);
//PS;
return 0;
}