Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define all(c) c.begin(),c.end()
- using namespace std;
- typedef long long ll;
- const ll INF64 = 1e18 + 1337;
- const int INF32 = 1e9 + 228;
- const int MOD = 1e9 + 7;
- int main()
- {
- ios_base::sync_with_stdio(0);
- #ifndef __WIN32
- ifstream cin("input.txt");
- ofstream cout("output.txt");
- #endif
- cin.tie(0);cout.tie(0);
- int n;
- cin >> n;
- vector<int> a(n);
- for(auto& it : a) cin >> it;
- vector<int> p(n, 0);
- for(int i = 1; i < n; i++)
- {
- int j = p[i - 1];
- while(j > 0 && a[i] != a[j])
- {
- j = p[j - 1];
- }
- if(a[i] == a[j]) j++;
- p[i] = j;
- }
- for(int i = n - 1; i >= 0; i--)
- {
- if(p[i] == 1)
- {
- cout << ((((p[n - 1] - 1) % i) == 0) ? i : n - 1);
- return 0;
- }
- }
- #ifndef __WIN32
- cin.close();
- cout.close();
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement