Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <map>
- using namespace std;
- typedef long long ll;
- const int alphabet_size = 26;
- const int maxn = 300;
- int trie[maxn][alphabet_size];
- map<int, int> at_trie_end_of_word;
- int main()
- {
- ios_base::sync_with_stdio(false);
- int o, n;
- cin >> o >> n;
- vector<string> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- }
- map<string, int> m1;
- map<int, string> m2;
- int cnt = 1;
- for(int i = 0; i < n; i++) {
- string tmp = "";
- for(int j = 0; j < (int) v[i].size(); j++) {
- tmp += v[i][j];
- m1[tmp] = cnt;
- m2[cnt] = tmp;
- cnt++;
- }
- }
- m1[""] = 0;
- m2[0] = "";
- for(int idx = 0; idx <= maxn; idx++) {
- if(m2.find(idx) != m2.end()) {
- for(int j = 0; j < n; j++) {
- if((int) m2[idx].size() >= (int) v[j].size() and m2[idx].find(v[j]) != string::npos) {
- at_trie_end_of_word[idx] |= (1 << j);
- }
- }
- }
- string tmp = "";
- for(int j = 0; j < 26; j++) {
- tmp = m2[idx] + (char) (j + 'a');
- while(m1.find(tmp) == m1.end()) {
- tmp.erase(tmp.begin());
- }
- trie[idx][j] = m1[tmp];
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement