Wrong Answer in RAINBOWA

I don’t know why I am getting wrong answer…

#include 

using namespace std;
int main()
{
    int a[7], a1[7], h = 0;
    int t, n;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        for(int m = 0; m < 7; m++)
        {
            a[m] = 0;
            a1[m] = 0;
        }
        cin >> n;
        int b[n];
        for(int j = 0; j < n; j++)
            cin >> b[j];
        if(b[0] == 1)
        {
            a[0]++;
        for(int j = 0; j < n-1; j++)
        {
            if(b[j+1] == b[j]+1 || b[j+1] == b[j])
                a[b[j+1]-1]++;
            else
            {
                if(b[j] != 7)
                {
                    h = 1;
                    break;
                }
                int z  = 0;
                for(int k = 0; k < 7; k++)
                {
                    if(a[k] == 0)
                    {
                        z = 1;
                        break;
                    }
                }
                if(z == 1)
                {
                    h = 1;
                    break;
                }

                z = 0;
                if(b[j+1] == 6)
                {
                    a1[5]++;
                for(int k = j+1; k < n-1; k++)
                {
                    if(b[k+1] == b[k]-1 || b[k+1] == b[k])
                    {
                        a1[b[k+1]-1]++;
                    }
                    else if(b[k+1] > b[k])
                    {
                        z = 1;
                        break;
                    }
                }
                }
                else
                {
                    h = 1;
                    break;
                }

                if(z == 1)
                {
                    h = 1;
                    break;
                }

                z = 0;
                for(int k = 0; k < 6; k++)
                {
                    if(a[k] != a1[k])
                    {
                        z = 1;
                        break;
                    }
                }
                //if(a[6] % 2 == 0)
                    //z = 1;
                if(z == 1)
                    h = 1;
                break;
            }
        }}
        else
            h = 1;
        if(h == 0)
            cout << "yes\n";
        else
            cout << "no\n";
        h = 0;
    }
    return 0;
}
1 Like

+Upvote for proper formatted code. :smiley:

Thanks @vijju123… Can anyone help me with this?

I can give it a look tomorrow morning if it suits you. Got some work right now :slight_smile:

EDIT: Giving a look now, lets not make you wait :slight_smile:

Okay sure… Thanks… :smiley:

you can see my submission to this question…i solved it today onlyy…as it is long code of your…it will definately lead to some confusion even for a good programme,…try to write less and effective …check it at
https://www.codechef.com/viewsolution/15121952
the approach is very simple
2 steps

1*    check if it is palindrome number or not(i think u know it)

2*then check whether it has all 7 digits or not
(assuming input in ascending order )

:slight_smile:

Here you go-

Input
1
7
1 2 3 4 5 6 7
Your output
yes
Expected Output
no

Thank You very much for pointing out the problem :slight_smile:

My pleasure dear :slight_smile:

Finally relaxed after getting the green tick… Thank You again :slight_smile:
https://www.codechef.com/viewsolution/15133311

I know my code is not elegant and may be not that effective…
I like your logic of checking for palindrome number but I think there is one problem in the code.

It should not satisfy this test case which it does:

19
1 2 3 4 4 5 8 6 6 7 6 6 8 5 4 4 3 2 1

because 1, 2, 3… 7 should be sequential as far as I have understood. :slight_smile: