egogoboy

Поле Чудес

May 31st, 2022
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <stdio.h>
  5.  
  6. using namespace std;
  7.  
  8. bool search(int k, int j, vector<int> m, int n) {
  9.     int temp = m[j];
  10.     for (int i = j + k; i < n - 1; i+= k) {
  11.         if (temp != m[i]) {
  12.             return false;
  13.         }
  14.     }
  15.  
  16.     return true;
  17. }
  18.  
  19. int main() {
  20.  
  21.     //std::ifstream fin("input.txt");
  22.     //std::ofstream fout("output.txt");
  23.  
  24.     int n;
  25.     cin >> n;
  26.     vector<int> m(n);
  27.     bool f = true;
  28.  
  29.     scanf_s("%d", &m[0]);
  30.     for (int i = 1; i < n; i++) {
  31.         scanf_s("%d", &m[i]);
  32.         if (m[0] != m[i] && f) {
  33.             f = !f;
  34.         }
  35.     }
  36.  
  37.     if (f) {
  38.         printf("%d", 1);
  39.         return 0;
  40.     }
  41.  
  42.     for (int i = 2; i <= (n - 1) / 2; i++) {
  43.         bool f = true;
  44.         if (m[0] == m[i] && (n-1) % i == 0) {
  45.             for (int j = 0; j <= i && f; j++) {
  46.                 f = search(i, j, m, n);
  47.             }
  48.         }
  49.         else {
  50.             f = !f;
  51.         }
  52.         if (f) {
  53.             printf("%d", i);
  54.             return 0;
  55.         }
  56.     }
  57.  
  58.     printf("%d", n - 1);
  59.     return 0;
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment