Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. const int max_n = 1e5 + 228;
  2. int go[max_n][26];
  3. int sz[max_n];
  4. bool is_term[max_n];
  5. int count_of_note;
  6.  
  7. int add_string(string s) {
  8.     int just = 0;
  9.     int cnt = 0;
  10.     int ans = s.size();
  11.     for (int i = 0; i < s.size(); i++) {
  12.         if (sz[just] == 1) {
  13.             cnt++;
  14.         }
  15.         if (!go[just][s[i] - 'a']) {
  16.             if (is_term[just]) {
  17.                 ans -= max(0, cnt - 1);
  18.             }
  19.             count_of_note++;
  20.             go[just][s[i] - 'a'] = count_of_note;
  21.         }
  22.         sz[just]++;
  23.         just = go[just][s[i] - 'a'];
  24.     }
  25.     sz[just]++;
  26.     is_term[just] = true;
  27.     return ans;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement