-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.cpp
103 lines (100 loc) · 2.11 KB
/
D.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
int ara[200005],ans[200005];
int main()
{
fastio;
int t,n,i,cnt;
cin>>t;
while(t--)
{
cnt=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>ara[i];
if(i>0)
{
if(ara[i]!=ara[i-1])
cnt++;
}
if(i==n-1)
{
if(ara[0]!=ara[n-1])
cnt++;
}
}
//cout<<cnt<<"\n";
if(cnt==0)
{
cout<<1<<"\n";
for(i=0;i<n;i++)
cout<<1<<" ";
cout<<"\n";
continue;
}
if(n%2==0)
{
cout<<2<<"\n";
for(i=0;i<n;i++)
{
cout<<1+(i%2)<<" ";
}
cout<<"\n";
continue;
}
if(cnt==n)
{
cout<<3<<"\n";
for(i=0;i<n-1;i++)
{
cout<<1+(i%2)<<" ";
}
cout<<3<<" ";
cout<<"\n";
}
else
{
cout<<2<<"\n";
for(i=0;i<n;i++)
{
ans[i]=1+(i%2);
}
int f=0;
for(i=1;i<n;i++)
{
if(ara[i]==ara[i-1])
{
ans[i]=ans[i-1];
f=i;
break;
}
}
if(f!=0)
{
for(i=f+1;i<n;i++)
{
if(ans[i]==1)
ans[i]=2;
else
ans[i]=1;
}
}
// else
// {
// for(i=0;i<n-1;i++)
// {
// if(ans[i]==1)
// ans[i]=2;
// else
// ans[i]=1;
// }
// }
for(i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<"\n";
}
}
return 0;
}