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. set<pii> chk;
  44. const int M1 = 1e9 + 7;
  45. const int M2 = 1e5 + 3;
  46. int main() {
  47. string s;
  48. cin >> s;
  49. for (int i = 0; i < s.size(); ++i) {
  50. int H1 = 0, H2 = 0;
  51. for (int j = i; j < s.size(); ++j) {
  52. int c = s[j] - 'a' + 1;
  53. H1 = (27ll * H1 + c) % M1;
  54. H2 = (27ll * H2 + c) % M2;
  55. chk.insert(pii(H1, H2));
  56. }
  57. }
  58. cout << chk.size() << '\n';
  59. }
  60.  
Success #stdin #stdout 0s 15240KB
stdin
ababc
stdout
12