-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarousel.cpp
89 lines (89 loc) · 1.29 KB
/
carousel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(void)
{
fastio;
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
int index=-1;
for(int i=1;i<n-1;i++)
{
if(arr[i]==arr[i-1] && arr[i]!=arr[i+1])
{
index=i;
}
}
int a[n];
a[0]=1;
int flag2=0,flag3=0;
for(int i=1;i<n;i++)
{
if(arr[i]==arr[i-1])
{
a[i]=a[i-1];
}
else
{
if(a[i-1]==1)
{
a[i]=2;
flag2=1;
}
else
{
a[i]=1;
}
}
}
if(arr[n-1]!=arr[0] && a[n-1]==1)
{
if(a[n-2]==1)
{
a[n-1]=2;
flag2=1;
}
else if(index==-1)
{
a[n-1]=3;
flag3=1;
}
else
{
for(int i=index;i<n;i++)
{
if(a[i]==1){a[i]=2;flag2=1;}
else
a[i]=1;
}
}
}
if(flag3==1)
{
cout<<3<<"\n";
}
else if(flag2==1)
{
cout<<2<<"\n";
}
else
{
cout<<1<<"\n";
}
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
cout<<"\n";
}
}