Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 8e6 + 5;
- int n, trie[N][26], cnt = 1;
- int isEnd[N];
- vector<string> ans;
- string a;
- void insert(string s){
- int u = 1;
- for(int i = 0; i < s.size(); i++){
- char x = s[i] - 'a';
- if(trie[u][x]) u = trie[u][x];
- else trie[u][x] = ++cnt, u = cnt;
- }
- if(isEnd[u]) ans.push_back(s);
- isEnd[u]++;
- }
- int main(){
- ios_base::sync_with_stdio(0), cin.tie(0);
- cin >> n;
- while(n--){
- cin >> a;
- if(a.size() >= 4) insert(a);
- }
- if(!ans.size()) cout << "SAFO" << endl;
- else cout << ans.size() << endl;
- for(auto &x : ans) cout << x << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement