SHARE
TWEET

Untitled

a guest Sep 16th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. const int N = 5e5+5;
  7. int n, a[N], b[N], k = 1, id;
  8. bool nice;
  9.  
  10. int main(){
  11.     ios_base::sync_with_stdio(0);
  12.     cin.tie(0);
  13.     cin >> n;
  14.     for(int i = 0; i < n; ++i)
  15.         cin >> a[i];
  16.     b[0] = 1;
  17.     for(int i = 1; i < n; ++i){
  18.         if(a[i]!=a[i-1]) k = 2, b[i] = 2-(!(b[i-1]%2));
  19.         else b[i] = b[i-1], nice = true, id = i;
  20.     }
  21.     if(a[n-1]!=a[0]&&a[n-1]!=a[n-2]&&b[0]!=b[n-2]) b[n-1] = ++k;
  22.     else if(a[n-1]!=a[0]&&b[n-1]==b[0])  k = 2, b[n-1] = 2-(!(b[0]%2));
  23.     if(k==3&&nice){
  24.         k = 2;
  25.         b[id] = 2-!(b[id-1]%2);
  26.         for(int i = id+1; i < n; ++i){
  27.             if(a[i]!=a[i-1]) b[i] = 2-(!(b[i-1]%2));
  28.             else b[i] = b[i-1];
  29.         }
  30.         if(a[n-1]!=a[0]&&a[n-1]!=a[n-2]&&b[0]!=b[n-2]) b[n-1] = ++k;
  31.         else if(a[n-1]!=a[0]&&b[n-1]==b[0])  k = 2, b[n-1] = 2-(!(b[0]%2));
  32.     }
  33.     cout << k << endl;
  34.     for(int i = 0; i < n; ++i)
  35.         cout << b[i] << " ";
  36.  
  37.     return 0;
  38.     }
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