SHARE
TWEET

Untitled

a guest Nov 7th, 2018 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n, t;
  8.     cin >> n >> t;
  9.     vector <int> s(n);
  10.     for (int i = 0; i < n; i++)
  11.     {
  12.         cin >> s[i];
  13.     }
  14.     vector <int long long> answer;
  15.     vector<int long long>d (n, 0);
  16.     answer.push_back(n);
  17.     int long long l = 0;
  18.     int long long r = 0;
  19.     for (int long long i = 1; i < (s.size() / 2) + 1; i++)
  20.     {
  21.         if (i < r)
  22.             d[i] = min(d[l + r - i + 1], r - i + 1);
  23.         int long long L = i - d[i], R = i + d[i] - 1;
  24.         while(L - 1 >= 0 && R + 1< n && s[L - 1] == s[R + 1]) d[i]++, L--, R++;
  25.         if (d[i] - i == 0)
  26.         {
  27.             answer.push_back(n - i);
  28.         }
  29.         if (R > r)
  30.             l = L, r = R;
  31.     }
  32.     sort(answer.begin(), answer.end());
  33.     for (int i = 0; i< answer.size(); i++)
  34.     {  
  35.         if (i < answer.size() - 1)
  36.                 cout << answer[i] << " ";
  37.         else
  38.                 cout << answer[i];
  39.     }
  40.     return 0;
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top