Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.23 KB | None | 0 0
  1. #pragma GCC omptimize("unroll-loops")
  2. #pragma GCC omptimize("игорь говно")
  3. #pragma GCC optimize("no-stack-protector")
  4. #pragma comment(linker, "/STACK:1000000000")
  5.  
  6. #include <iostream>
  7. #include <cmath>
  8. #include <iostream>
  9. #include <vector>
  10. #include <algorithm>
  11. #include <string>
  12. #include <set>
  13. #include <map>
  14. #include <list>
  15. #include <time.h>
  16. #include <math.h>
  17. #include <random>
  18. #include <deque>
  19. #include <queue>
  20. #include <cassert>
  21. #include <unordered_map>
  22. #include <unordered_set>
  23. #include <iomanip>
  24. #include <bitset>
  25. #include <sstream>
  26. #include <chrono>
  27.     #define LOCAL
  28.     #define fori(i, r, x) for(int i = r; i < x; i++)
  29.     #define eb emplace_back
  30.     #define lb lower_bound
  31.     #define ub upper_bound
  32.     #define er equal_range
  33.     #define fi first
  34.     #define se second
  35.  
  36.     using namespace std;
  37.  
  38.     typedef long long int lli;
  39.     typedef long long ll;
  40.     typedef long double ld;
  41.     typedef pair<int, int> pii;
  42.     typedef pair<ll,ll> pll;
  43.     typedef pair<ld,ld> pld;
  44.     typedef vector<int> vi;
  45.     typedef vector<ll> vll;
  46.     typedef vector<ld> vld;
  47.     typedef vector<vector<int>> vvi;
  48.  
  49.     const int INF32 = 2009000999;
  50.     const ll INF64 = 4e18;
  51.     const int sz = 1e6;
  52.     const int mod = 1e9+7;
  53.     const long double EPS = 1e-18;
  54.     const int base = 1000*1000*1000;
  55.     const int p = 31;
  56.    
  57.  
  58.     string s;
  59.     ll cnt = 0, n;
  60.    
  61.     ll haash(string a) {
  62.         long long hashh = 0, p_pow = 1;
  63.         for (size_t i=0; i<a.size(); i++)  {
  64.             hashh += (a[i] - 'a' + 1) * p_pow;
  65.             p_pow *= p;
  66.         }
  67.         return hashh;
  68.     }
  69.     void step() {
  70.         int st, stt;
  71.         ll sttt = s[0];
  72.         for(int i = n - 1; i >= 0; i--) {
  73.             if (i == n - 1) {
  74.                 stt = s[i];
  75.                 s[i] = sttt;
  76.             }
  77.            
  78.             else {
  79.                 st = s[i];
  80.                 s[i] = stt;
  81.                 stt = st;
  82.             }
  83.  
  84.         }
  85.     }
  86.     ll b, c;
  87.     int main(){
  88.         ios_base::sync_with_stdio(false);
  89.         cin.tie(0);
  90.         cout.tie(0);
  91.  
  92.         #ifndef LOCAL
  93.             freopen("input.txt", "r", stdin);
  94.             freopen("output.txt", "w", stdout);
  95.         #endif
  96.         cin >> n;
  97.         cin >> s;
  98.         string s1(s);
  99.         reverse(s1.begin(), s1.end());
  100.        
  101.         b = haash(s);
  102.        // cerr << b << endl;
  103.         c = haash(s1);
  104.        // for(int i = 0; i < s.size() - 1; i++) step();
  105.  
  106.        // cerr << c << endl;
  107.       //  cerr << haash(s) << endl;
  108.         if (b == c) {
  109.             cout << "0";
  110.             return 0;
  111.         }
  112.         ll k = 0;
  113.        // cerr << s << endl;
  114.        // cerr << s1 << endl;
  115.        //step();
  116.      //cerr << s << endl;
  117.         cnt = 0;
  118.         ll ans = 0;
  119.         for(int i = 0; i < s.size(); i++) {
  120.             step();
  121.            // cerr << s << endl;
  122.             if (haash(s) == c) {
  123.                 ans = cnt + 1;
  124.                 cout << ans;
  125.                 return 0;
  126.             }
  127.             else if (haash(s) == b){
  128.                 cout << -1;
  129.                 return 0;
  130.             }
  131.             else {
  132.                 cnt++;
  133.             }
  134.         }
  135.  
  136.         cout << cnt;
  137.         return 0;
  138.        
  139.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement