fork download
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cassert>
  4. #include <cstring>
  5. #include <iostream>
  6. #include <cmath>
  7. #include <deque>
  8. #include <queue>
  9. #include <stack>
  10. #include <vector>
  11. #include <algorithm>
  12. #include <set>
  13. #include <map>
  14. #include <complex>
  15.  
  16. #define mp(a, b) make_pair((a), (b))
  17. #define pb(a) push_back((a))
  18. #define pf(a) push_front((a))
  19. #define rb() pop_back()
  20. #define rf() pop_front()
  21. #define sz(a) ((int)a.size())
  22.  
  23. using namespace std;
  24.  
  25. typedef long long lld;
  26. typedef pair<int, int> pii;
  27. typedef pair<lld, lld> pll;
  28. typedef pair<lld, int> pli;
  29. typedef pair<int, lld> pil;
  30. typedef vector<vector<int>> Matrix;
  31. typedef vector<vector<int>> Adj;
  32. typedef vector<int> Row;
  33. typedef complex<double> Complex;
  34. typedef vector<Complex> Vcomplex;
  35.  
  36. const int MOD = 1e9 + 7;
  37. const int INF = 1e9;
  38. const lld LINF = 1e18;
  39. const double FINF = 1e15;
  40. const double EPS = 1e-9;
  41. const double PI = 2.0 * acos(0.0);
  42.  
  43.  
  44. int nxt[1000005][26];
  45. bool chk[1000005];
  46. int root = 1;
  47. int id = 1;
  48. int main() {
  49. string s;
  50. cin >> s;
  51. for (int i = 0; i < s.size(); ++i) {
  52. int cur = root;
  53. for (int j = i; j < s.size(); ++j) {
  54. int c = s[j] - 'a';
  55. if (nxt[cur][c] == 0) nxt[cur][c] = ++id;
  56. cur = nxt[cur][c];
  57. chk[cur] = true;
  58. }
  59. }
  60. cout << id - 1 << '\n';
  61. }
  62.  
Success #stdin #stdout 0s 117760KB
stdin
ababc
stdout
12