fork download
  1. #include<iostream>
  2. #include<string>
  3. #include<map>
  4. #include<vector>
  5. #include<queue>
  6. #include<stack>
  7. #include<set>
  8. #include<algorithm>
  9. #include<sstream>
  10. #include<limits.h>
  11. #include<iomanip>
  12. #include<cstring>
  13. #include<bitset>
  14. #include<fstream>
  15. #include<cmath>
  16. #include<cassert>
  17. #include <stdio.h>
  18. #include<ctype.h>
  19. using namespace std;
  20. vector <int> ZFunction(string &str) {
  21. vector <int> Z(str.size(), 0);
  22. int L = 0, R = 0;
  23. for(int i = 1; i < str.size(); ++ i) {
  24. if (i > R || Z[i - L] >= R - i + 1) {
  25. L = i; R = max(i, R);
  26. while (R < str.size() && str[R - L] == str[R]) R ++;
  27. Z[i] = (R --) - L;
  28. } else
  29. Z[i] = Z[i - L];
  30. }
  31. Z[0] = str.size();
  32. return Z;
  33. }
  34. int thirdPattern(vector<int> &Z) {
  35. int res = 0;
  36. for(int i = 1; i < Z.size(); ++ i)
  37. if(Z[i] >= i && i * 2 < Z.size())
  38. res ++;
  39. return res;
  40. }
  41. int secondPattern(vector<int> &Z) {
  42. int res = 0;
  43. for(int i = 1; i < Z.size(); ++ i)
  44. if(Z[i] + i == Z.size() && Z[i] * 2 < Z.size())
  45. res ++;
  46. return res;
  47. }
  48.  
  49. int main() {
  50. // freopen("input.txt","r",stdin);
  51. string str, rev;
  52. while(cin >> str) {
  53.  
  54. rev = str;
  55. reverse(rev.begin(), rev.end());
  56.  
  57. vector<int> Z = ZFunction(str);
  58. vector<int> Z_rev = ZFunction(rev);
  59.  
  60. int res = thirdPattern(Z_rev);
  61. res += secondPattern(Z);
  62. res += thirdPattern(Z);
  63.  
  64. cout << res << endl;
  65. }
  66. }
Success #stdin #stdout 0s 3144KB
stdin
Standard input is empty
stdout
Standard output is empty