Problem Description
Chefs new hobby is painting, but he learned the fact that its not easy to paint 2D pictures in a hard way, after wasting a lot of canvas paper, paint and of course time. From now on, he decided to paint 1D pictures only.
Chefs canvas is N millimeters long and is initially all white. For simplicity, colors will be represented by an integer between 0 and 105. 0 indicates white. The picture he is envisioning is also N millimeters long and the ith millimeter consists purely of the color Ci. Unfortunately, his brush isnt fine enough to paint every millimeter one by one. The brush is 3 millimeters wide and so it can only paint three millimeters at a timewith the same color. Painting over the same place completely replaces the color by the new one. Also, Chef has lots of bottles of paints of each color, so he will never run out of paint of any color.
Chef also doesnt want to ruin the edges of the canvas, so he doesnt want to paint any part beyond the painting. This means, for example, Chef cannot paint just the first millimeter of the canvas, or just the last two millimeters, etc.
Help Chef by telling him whether he can finish the painting or not with these restrictions.
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N. The second line contains N space-separated integers C1, C2, ..., CNCODING ARENA
#include <stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int i,flag=0,n;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=1;i<n;i++)
{
if(a[i]==a[i-1] && a[i]==a[i+1])
flag=1;
}
if(flag==1)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
Test Case 1
Input (stdin)3 4 1 5 5 5 4 1 1 1 5 3 5 5 2
Expected OutputYes Yes No
Test Case 2
Input (stdin)2 3 1 1 1 2 10 10
Expected OutputYes No
No comments:
Post a Comment