Advertisement
Josif_tepe

Untitled

Dec 23rd, 2023
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <map>
  5. using namespace std;
  6. typedef long long ll;
  7. const int alphabet_size = 26;
  8. const int maxn = 300;
  9. int trie[maxn][alphabet_size];
  10. map<int, int> at_trie_end_of_word;
  11. int main()
  12. {
  13.     ios_base::sync_with_stdio(false);
  14.     int o, n;
  15.     cin >> o >> n;
  16.    
  17.     vector<string> v(n);
  18.     for(int i = 0; i < n; i++) {
  19.         cin >> v[i];
  20.     }
  21.     map<string, int> m1;
  22.     map<int, string> m2;
  23.     int cnt = 1;
  24.     for(int i = 0; i < n; i++) {
  25.         string tmp = "";
  26.         for(int j = 0; j < (int) v[i].size(); j++) {
  27.             tmp += v[i][j];
  28.             m1[tmp] = cnt;
  29.             m2[cnt] = tmp;
  30.             cnt++;
  31.         }
  32.     }
  33.     m1[""] = 0;
  34.     m2[0] = "";
  35.    
  36.     for(int idx = 0; idx <= maxn; idx++) {
  37.         if(m2.find(idx) != m2.end()) {
  38.             for(int j = 0; j < n; j++) {
  39.                 if((int) m2[idx].size() >= (int) v[j].size() and m2[idx].find(v[j]) != string::npos) {
  40.                     at_trie_end_of_word[idx] |= (1 << j);
  41.                    
  42.                 }
  43.             }
  44.         }
  45.         string tmp = "";
  46.         for(int j = 0; j < 26; j++) {
  47.             tmp = m2[idx] + (char) (j + 'a');
  48.             while(m1.find(tmp) == m1.end()) {
  49.                 tmp.erase(tmp.begin());
  50.             }
  51.             trie[idx][j] = m1[tmp];
  52.         }
  53.     }
  54.    
  55.     return 0;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement