SHARE
TWEET

Untitled

a guest Jun 19th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 8e6 + 5;
  5.  
  6. int n, trie[N][26], cnt = 1;
  7. int isEnd[N];
  8. vector<string> ans;
  9. string a;
  10.  
  11. void insert(string s){
  12.   int u = 1;
  13.   for(int i = 0; i < s.size(); i++){
  14.     char x = s[i] - 'a';
  15.     if(trie[u][x]) u = trie[u][x];
  16.     else trie[u][x] = ++cnt, u = cnt;
  17.   }
  18.   if(isEnd[u]) ans.push_back(s);
  19.   isEnd[u]++;
  20. }
  21.  
  22. int main(){
  23.   ios_base::sync_with_stdio(0), cin.tie(0);
  24.   cin >> n;
  25.   while(n--){
  26.     cin >> a;
  27.     if(a.size() >= 4) insert(a);
  28.   }
  29.  
  30.   if(!ans.size()) cout << "SAFO" << endl;
  31.   else cout << ans.size() << endl;
  32.   for(auto &x : ans) cout << x << endl;
  33.  
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top