Advertisement
Korotkodul

Глебу

Jun 14th, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17.     for (auto x: v) cout<<x<<' ';
  18.     cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22.     for (auto x: v) cout<<x<<' ';
  23.     cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28.     for (auto x: v) cv(x);
  29.     cout<<"\n";
  30. }
  31.  
  32. int n,why;
  33.  
  34. vector <int> S;
  35.  
  36.  
  37.  
  38. vector <int> ans;
  39.  
  40. vector <int> m;
  41.  
  42. void mnk(){
  43.     n = S.size();
  44.     m.resize(n,0);
  45.     //cout<<"S\n";
  46.     //cv(S);
  47.     pii lr = {-1, -1};
  48.     pii now;
  49.     for (int i = 0; i < n;++i){
  50.         int l = lr.first, r = lr.second;
  51.         if (i >= l && i <= r){
  52.             int idx = l +  (r - i);
  53.             m[i] = min(r - i + 1, m[idx]);
  54.         }
  55.         while (i - m[i] >= 0 && i + m[i] < n && S[i - m[i]] == S[i + m[i]]){
  56.             ++m[i];
  57.         }
  58.         now = {i - m[i] + 1, i + m[i] - 1};
  59.         if (now.second > lr.second){
  60.             lr = now;
  61.         }
  62.     }
  63.     //cout<<"m\n";
  64.     //cv(m);
  65.     int k=-1;
  66.     for (int i = 0; i < n; i+=2){
  67.         if (i - m[i] == -1){
  68.             k = (n - i) / 2;
  69.             ans.push_back(k);
  70.         }
  71.     }
  72. }
  73.  
  74. int main()
  75. {
  76.     ios::sync_with_stdio(0);
  77.     cin.tie(0);
  78.     cout.tie(0);
  79.     cin>>n>>why;
  80.     S = {0};
  81.     for (int i=0;i<n;++i) {
  82.             int x;
  83.             cin>>x;
  84.             S.push_back(x);
  85.             S.push_back(0);
  86.     }
  87.     mnk();
  88.     sort(ans.begin(), ans.end());
  89.     //cout<<"ans\n";
  90.     cv(ans);
  91. }
  92. /*
  93. 6 2
  94. 1 1 2 2 1 1
  95.  
  96. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement