Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <iomanip>
  5. #include <sstream>
  6. #include <cstdio>
  7. #include <bitset>
  8. #include <vector>
  9. #include <queue>
  10. #include <cmath>
  11. #include <stack>
  12. #include <set>
  13. #include <map>
  14.  
  15. #define ft first
  16. #define sd second
  17. #define pb push_back
  18. #define pf push_front
  19. #define mk make_pair
  20. #define all(c) (c).begin(), (c).end()
  21. #define SWS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  22. #define rfile freopen("input.txt", "r", stdin)
  23. #define wfile freopen("output.txt", "w", stdout)
  24. #define files rfile; wfile
  25. #define DEBUG 1
  26.  
  27. typedef long long ll;
  28. typedef unsigned long long ull;
  29.  
  30. using namespace std;
  31.  
  32. const int Z = 3 * (int)1e5 + 111;
  33. const int INF = (int)1e9 + 111;
  34. const int MODF = (int)1e9 + 7;
  35.  
  36. string ss;
  37.  
  38. void check(string s, string t) {
  39.   s.erase(s.begin(), s.begin() + t.size());
  40.   s += t;
  41.   if (s != ss) {
  42.     cout << 1 << '\n';
  43.     exit(0);
  44.   }
  45. }
  46.  
  47. void rec(string s, string t) {
  48.   if (t.size() % 2 != 0 || t.size() == 0)
  49.     return;
  50.   string a = t.substr(0, t.size() / 2);
  51.   string b = t.substr(t.size() / 2 + t.size() % 2, t.size() / 2);
  52.   reverse(b.begin(), b.end());
  53. //  cout << a << '\n' << b << '\n';
  54. //  cout << t.substr(0, t.size() / 2) << '\n';
  55. //  cout << t.substr(t.size() / 2 + t.size() % 2, t.size() / 2) << '\n';
  56.   if (a == b) {
  57.  
  58.     check(s, a);
  59.     rec(s, a);
  60.   }
  61.    
  62. }
  63.  
  64. int main() {
  65.   SWS;
  66.   string s;
  67.   int flag = 0;
  68.   cin >> s;
  69.   ss = s;
  70.   for (int i = 1; i < s.size(); i++)
  71.     if (s[i] != s[i - 1])
  72.       flag = 1;
  73.   if (!flag) {
  74.     cout << "Impossible";
  75.     return 0;
  76.   }
  77.   if (s.size() % 2 == 0) {
  78.     rec(s, s);
  79.     for (int i = 1; i <= s.size() / 2 - s.size() % 2; i++)
  80.       if (s[i] != s[i - 1])
  81.         flag = 1;
  82.     if (!flag) {
  83.       cout << "Impossible";
  84.       return 0;
  85.     }
  86.     cout << 2 << '\n';
  87.     return 0;
  88.   }
  89.    
  90.   else {
  91.     flag = 0;
  92.     for (int i = 1; i <= s.size() / 2 - s.size() % 2; i++)
  93.       if (s[i] != s[i - 1])
  94.         flag = 1;
  95.     if (!flag) {
  96.       cout << "Impossible";
  97.       return 0;
  98.     }
  99.     cout << 2;
  100.     return 0;
  101.   }
  102.   cout << 3;
  103.  
  104.   return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement