Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <unordered_map>
- using namespace std;
- class Trie{
- struct Node {
- unordered_map<char, Node> next;
- int isTerminal = 0;
- bool visited = false;
- }
- root;
- public:
- int symb_cnt = 0;
- void Insert(const string& s) {
- Node* cur = &root;
- for (auto c: s) {
- cur = &cur->next[c];
- if (!cur->visited){
- ++symb_cnt;
- cur->visited = true;
- }
- }
- ++cur->isTerminal;
- }
- };
- int main() {
- int n;
- cin >> n;
- Trie trie;
- int summ = 0;
- for (int i = 0; i < n; ++i){
- string s;
- cin >> s;
- summ += s.size();
- trie.Insert(s);
- }
- cout << summ - trie.symb_cnt;
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement