Advertisement
ivnikkk

Untitled

Oct 26th, 2021
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <iomanip>
  6. #include <fstream>
  7. #include <string>
  8. #include <set>
  9. #include <deque>
  10. #include <queue>
  11. #include <map>
  12. #include <bitset>
  13. #include <random>
  14. #include <cassert>
  15.  
  16. using namespace std;
  17.  
  18. typedef long long            ll;
  19. typedef unsigned long long   ull;
  20. typedef long double          ld;
  21.  
  22. #define sqrt              sqrtl
  23. #define endl              "\n"
  24. #define all(a)            a.begin(), a.end()
  25. #define pb                push_back
  26. #define f1                first
  27. #define s2                second
  28.  
  29. const ll       inf = 1e9;
  30. long double    eps = 1e-18;
  31. ll             mod = 1e9 + 7;
  32. const ll         MAXN = 100010;
  33. const ll M = 1e9 + 7, m = 998244353;
  34. ll bb = 997;
  35. template <typename T>
  36. istream& operator >> (istream& in, vector <T>& a) {
  37.     for (T& i : a) {
  38.         in >> i;
  39.     }
  40.     return in;
  41. }
  42.  
  43. template <typename T>
  44. ostream& operator << (ostream& out, vector <T>& a) {
  45.     for (T& i : a) {
  46.         out << i << ' ';
  47.     }
  48.     return out;
  49. }
  50.  
  51. struct node{
  52.     ll next[26];
  53.     node(){
  54.         for (ll i = 0; i < 26; i++) next[i] = 0;
  55.     }
  56. };
  57. vector<node> bor(1);
  58. void build_bor(string &s) {
  59.     for (ll i = 0; i < s.size(); i++) {
  60.         ll now = 0;
  61.         for (ll j = i; j < s.size(); j++) {
  62.             char term = s[j] - 'a';
  63.             if (bor[now].next[term] == 0) {
  64.                 bor[now].next[term] = bor.size();
  65.                 node vert;
  66.                 bor.push_back(vert);
  67.             }
  68.             now = bor[now].next[term];
  69.         }
  70.     }
  71. }
  72. void solve() {
  73.     string s;
  74.     cin >> s;
  75.     build_bor(s);
  76.     cout << bor.size()-1;
  77. }
  78. signed main() {
  79.     ios_base::sync_with_stdio(false);
  80.     cin.tie(nullptr);
  81.     ll t = 1;
  82.     //cin >> t;
  83.     while (t--) solve();
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement