fork(7) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int solveOdd(const string& s) {
  5. return 2;
  6. }
  7.  
  8. int solveEven(const string& s) {
  9. if (s.length() % 2 == 1) {
  10. return 2;
  11. }
  12. string lf = s.substr(0, s.length() / 2);
  13. string rg = s.substr(s.length() / 2, s.length() / 2);
  14. if (lf != rg) return 1;
  15. return solveEven(lf);
  16. }
  17.  
  18.  
  19. int32_t main() {
  20. ios_base::sync_with_stdio(false);
  21. cin.tie(nullptr), cout.tie(nullptr);
  22.  
  23. string s;
  24. cin >> s;
  25. if (s.length() < 3) {
  26. cout << "Impossible" << endl;
  27. return 0;
  28. }
  29. vector<int> cnt(255);
  30. for(char c : s) {
  31. ++cnt[c];
  32. }
  33. if (*max_element(cnt.begin(), cnt.end()) >= s.length() - 1) {
  34. cout << "Impossible" << endl;
  35. return 0;
  36. }
  37. cout << (s.length() % 2 == 0 ? solveEven(s) : solveOdd(s)) << endl;
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Impossible