Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const int MAX_N = 100010;
- const int MAX_P = 60;
- char s[MAX_N];
- int ls;
- char p[MAX_P];
- class trieNode {
- public:
- unordered_map<char, trieNode*> nodes;
- char c;
- int match;
- trieNode(char c){
- this->c = c;
- this->match = 0;
- }
- void add(char* s, int len){
- trieNode* root = this;
- for(int i = 0;i<len;++i){
- if(root->nodes.find(s[i]-'a') == root->nodes.end()){
- root->nodes[s[i]-'a'] = new trieNode(s[i]);
- }
- root = root->nodes[s[i]-'a'];
- }
- (root->match)++;
- }
- int search(char* s, int len){
- trieNode* root = this;
- for(int i = 0;i<len;++i){
- if(root->nodes.find(s[i]-'a') == root->nodes.end()){
- return 0;
- }
- root = root->nodes[s[i]-'a'];
- }
- return root->match;
- }
- void deleteNode(){
- for(auto it = nodes.begin(); it != nodes.end();++it){
- it->second->deleteNode();
- }
- }
- };
- int getRes(int n){
- trieNode* root = new trieNode('\0');
- for(int i = 0;i<n;++i){
- cin>>p;
- root->add(p, strlen(p));
- }
- int res = 0;
- int lp = strlen(p);
- for(int i = 0;i<ls-lp+1;++i){
- res += root->search(s+i, lp);
- }
- root->deleteNode();
- delete root;
- return res;
- }
- int main(){
- ios::sync_with_stdio(false);
- int a, b, c;
- cin>>a>>b>>c;
- cin>>s;
- ls = strlen(s);
- int res = 0;
- res += getRes(a);
- res += getRes(b);
- res += getRes(c);
- cout<<res<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement