fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int main() {
  5. string s;
  6. cin >> s;
  7. int n = s.length();
  8. s += s;
  9. int len = s.length();
  10. vector <int> d (len);
  11. int l = 0, r = -1;
  12. if (n % 2) {
  13. for (int i = 0; i < len; ++i) {
  14. d[i] = (i > r)? 1 : min(d[l + r - i], r - i + 1);
  15. while (i - d[i] >= 0 and i + d[i] < len and s[i - d[i]] == s[i + d[i]])
  16. d[i]++;
  17. if (i + d[i] - 1 > r) {
  18. r = i + d[i] - 1;
  19. l = i - d[i] + 1;
  20. }
  21. if (r - l + 1 >= n) {
  22. cout << "yes";
  23. return 0;
  24. }
  25. }
  26. }
  27. else {
  28. for (int i = 0; i < len; ++i) {
  29. d[i] = (i > r)? 0 : min(d[l + r - i + 1], r - i + 1);
  30. while (i - d[i] - 1 >= 0 and i + d[i] < len and s[i - d[i] - 1] == s[i + d[i]])
  31. d[i]++;
  32. if (i + d[i] - 1 > r) {
  33. r = i + d[i] - 1;
  34. l = i - d[i];
  35. }
  36. if (r - l >= n) {
  37. cout << "yes";
  38. return 0;
  39. }
  40. }
  41. }
  42. cout << "no";
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 5584KB
stdin
Standard input is empty
stdout
no