fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <stdio.h>
  4. #include <string>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. const int MOD = 1000003;
  10. long long k;
  11. vector<unsigned int> h[MOD];
  12. char st[5010];
  13. unsigned long long p[5010];
  14. int len;
  15. unsigned int prevh;
  16.  
  17. void calcp()
  18. {
  19. p[0] = 1;
  20. for (int i = 1; i < len; i++)
  21. p[i] = p[i - 1] * 107;
  22. }
  23.  
  24. void findsubstr()
  25. {
  26. int ind = prevh % MOD;
  27. bool f = 0;
  28. for (int i = 0; i < h[ind].size(); i++)
  29. {
  30. if (h[ind][i] == prevh)
  31. {
  32. f = 1;
  33. break;
  34. }
  35. }
  36. if (f) return;
  37. h[ind].push_back(prevh);
  38. k++;
  39. }
  40.  
  41. int main()
  42. {
  43. scanf("%s", &st);
  44. len = strlen(st);
  45. calcp();
  46. for (int r = len - 1; r >= 0; r--)
  47. {
  48. for (int l = r; l >= 0; l--)
  49. {
  50. prevh = l == r ? st[l] - 'a' + 1 : (st[l] - 'a' + 1) * p[r - l] + prevh;
  51. findsubstr();
  52. }
  53. }
  54. printf("%I64d", k);
  55. return 0;
  56. }
  57.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
aaba
compilation info
prog.cpp: In function 'int main()':
prog.cpp:44: error: 'strlen' was not declared in this scope
stdout
Standard output is empty