RAINBOWA - Editorial

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

why sir its incrementing by 1 from 1 and is follows rainbow rules…can you explain why please?

Read the question more closely :slight_smile: What are the values of a_1,a_2, ... , a_7 for your testcase?

1 Like

ok sir:)

Could anyone please point out which cases I am missing
https://www.codechef.com/viewsolution/30560990
I decremented the elements by 1 after each recursion and checked if the first and last a1 elements are equal to 1

Your solution fails for the same testcase as this guy.

2 Likes

It depends on the number of 7’s in in the sequence
If the number of 7’s are even then you have an even number of elements in the array otherwise odd.

what about 1 2 3 4 3 2 1?
My code gives yes, but one of the AC codes I compiled gives NO.