RAINBOWA - Editorial

If you are looking for better editorial for the problem, you can visit to the following link:
Rainbow Array Editorial

2 Likes

This page keeps on refreshing so i cannot submit my answer. Can someone please help me?

Might be something to do with this:

?

@admin

Not able to Submit my code for this problem. Please help.

#include
using namespace std;
int main(){
int t;
cin>>t;
while(t–){
int n,flag=0;
cin>>n;
int a[n];
int y[7]={0};
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]==1||a[i]==2||a[i]==3||a[i]==4||a[i]==5||a[i]==6||a[i]==7)
y[a[i]-1]=1;
}
for(int i=0;i<7;i++){
if(y[i]==0){
flag=1;
// cout<<“error pos1”;
break;
}
}
for(int i=0;i<n/2 && !flag;i++){
if(a[i]!=a[n-i-1]){
flag=1;
// cout<<“error pos2”;
break;
}
}
if(flag==1)
cout<<“no”<<endl;
else
cout<<“yes”;
}
}
so that was my code ,can someone please point out why I am unable to get AC ?

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Edit:

Managed to decipher it - consider the testcase:

1 
13
1 2 3 4 5 7 6 7 5 4 3 2 1

Edit:

Also, you’re not printing a new line if the answer is yes.

2 Likes

please tell me if 1 2 3 4 5 6 7 7 6 5 4 3 2 1 is rainbow array or not with apt reason.

Yes, with a_1 = a_2 = a_3 = a_4 = a_5 = a_6 = 1 and a_7=2.

3 Likes

You can refer to the link: Rainbow Array Solution with Explanation.

Thanks for Reading
Peace :v:

1 Like

Can anyone help me out for which test case I am failing?

My Solution

Kindly let me know any test case in which my program is not passing.

if ( (int)v.size() != 13 ) { // why 13
puts(“no”);
return 0;
}

for ( int i = 0; i < 7; i++ ) {
	if ( v[i].first != i + 1 ) {
		puts("no");
		return 0;
	}
}

for ( int i = 7; i < 13; i++ ) {
	if ( v[i].first != 13 - i || v[i].second != v[12 - i].second ) {
		puts("no");
		return 0;
	}
}
can someone explain me this?

This is my accepted solution for this question on Codechef

#include <bits/stdc++.h>
using namespace std;
int main()
{
long t;
cin>>t;
while(t–)
{
long n;
cin>>n;
int p[n],flag=1,i;
for(i=0;i<n;i++)
cin>>p[i];
int chec[8]={0};

  for(i=0;i<n;i++)
  	  chec[p[i]]++;
  for(int i=1;i<7;i++)
    {
        if(chec[i]%2!=0||chec[i]==0||chec[7]==0)
        {
            flag=0;
            break;
        }
    }
    if(flag==0)
        cout<<"no"<<endl;
    else
        cout<<"yes"<<endl;

}
return 0;
}

This is Author Solution for the same question

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 105;
const int MAX = 100;

int a[MAXN];

int main() {
int T;
scanf("%d", &T);
assert(T >= 1 && T <= MAX);
while (T–) {
int n;
scanf("%d", &n);
assert(n >= 1 && n <= MAX);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
assert(a[i] >= 1 && a[i] <= MAX);
}
vector<pair<int, int> > cnts;
int cnt = 1, which = a[0];
for (int i = 1; i < n; i++) {
if (a[i] == a[i - 1]) {
cnt++;
} else {
cnts.push_back(make_pair(which, cnt));
which = a[i];
cnt = 1;
}
}
if (cnt > 0) {
cnts.push_back(make_pair(which, cnt));
}
int ok = true;
// cnt dentoes consecutive groups of equal numbers.
if (cnts.size() == 13) {
for (int i = 0; i < 13; i++) {
if (cnts[i] != cnts[13 - i - 1]) {
ok = false;
}
if (i < 7 && cnts[i].first != i + 1) {
ok = false;
}
}
} else {
ok = false;
}
puts(ok ? “yes” : “no”);
}
return 0;
}

Now Test case i have used is this
1
13
3 4 5 6 1 2 7 2 1 6 5 4 3

My accepted solution is giving yes for above test case while Author’s solution giving no for the same…

I have run several hundreds of codes of other people also for the same test case.Their answer is yes for above test .
But Editorial and Tester solution is giving no for the same.

Just want to ask Codechef Admins what is happening here .Even the guys who have made the question have not used the correct test cases for checking solutions.

1 Like

I have spend hours on this test case
1
13
3 4 5 6 1 2 7 2 1 6 5 4 3

I think that problem setter has not used correct test cases for solution checking.

The answer should be no; the testcases for this problem seem to be very weak.

4 Likes

https://www.codechef.com/viewsolution/30389060

can someone please check my code and spot what i am forgetting in my logic…it is giving wrong answer on task 0 ?

Consider the testcase:

1
15
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
1 Like

its outputting “yes”

1 Like

I know :slight_smile:

2 Likes

then sir what can be the problem…?

It should be outputting

no

1 Like