Advertisement
kostes

Untitled

Dec 16th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define all(c) c.begin(),c.end()
  4. using namespace std;
  5. typedef long long ll;
  6. const ll INF64 = 1e18 + 1337;
  7. const int INF32 = 1e9 + 228;
  8. const int MOD = 1e9 + 7;
  9. int main()
  10. {
  11. ios_base::sync_with_stdio(0);
  12. #ifndef __WIN32
  13. ifstream cin("input.txt");
  14. ofstream cout("output.txt");
  15. #endif
  16. cin.tie(0);cout.tie(0);
  17.  
  18. int n;
  19. cin >> n;
  20. vector<int> a(n);
  21. for(auto& it : a) cin >> it;
  22. vector<int> p(n, 0);
  23. for(int i = 1; i < n; i++)
  24. {
  25. int j = p[i - 1];
  26. while(j > 0 && a[i] != a[j])
  27. {
  28. j = p[j - 1];
  29. }
  30. if(a[i] == a[j]) j++;
  31. p[i] = j;
  32. }
  33. for(int i = n - 1; i >= 0; i--)
  34. {
  35. if(p[i] == 1)
  36. {
  37. cout << ((((p[n - 1] - 1) % i) == 0) ? i : n - 1);
  38. return 0;
  39. }
  40. }
  41.  
  42. #ifndef __WIN32
  43. cin.close();
  44. cout.close();
  45. #endif
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement