-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarousel.java
More file actions
68 lines (65 loc) · 1.98 KB
/
carousel.java
File metadata and controls
68 lines (65 loc) · 1.98 KB
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
import java.util.Scanner;
public class carousel {
public static void main(String[] args) throws Exception {
Scanner sc=new Scanner(System.in);
StringBuilder sb=new StringBuilder();
int q=sc.nextInt();
while(q-->0){
int n=sc.nextInt();
int[] t=new int[n];
boolean z=true;
for(int i=0;i<n;i++){
t[i]=sc.nextInt();
if(z){
if(i>0 && t[i]!=t[(i+1)%2])z=false;
}
}
if(z){
sb.append(1+"\n");
for(int i=0;i<n;i++)sb.append(1+" ");
sb.append("\n");
continue;
}
if(n%2==0){
sb.append(2+"\n");
for(int i=0;i<n;i++){
sb.append(i%2+1+" ");
}
sb.append("\n");
continue;
}
else{
z=false;
int index=-1;
for(int i=0;i<n;i++){
if(t[i]==t[(i+1)%n]){
z=true;
index=i;
break;
}
}
if(z){
sb.append(2+"\n");
int count=1;
for(int i=0;i<n;i++){
if(i==index ){
sb.append(count+" ");
continue;
}
else if(i==index+1)sb.append(count+" ");
else sb.append(count+" ");
if(count==1)count=2;
else count=1;
}
}
else{
sb.append(3+"\n");
for(int i=0;i<n-1;i++)sb.append(i%2+1+" ");
sb.append(3);
}
}
sb.append("\n");
}
System.out.println(sb);
}
}