## 10038 - Jolly Jumpers

Moderator: Board moderators

raj
Learning poster
Posts: 78
Joined: Fri Feb 15, 2013 5:39 pm

### Re: 10038 - Jolly Jumpers

[/quote]

Was the verdict "Wrong Answer" or "Runtime Error"?

[/quote]

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

### Re: 10038 - Jolly Jumpers

raj wrote: sir its "wrong answer"...........
You may try these cases:

Input

Code: Select all

``````10 0 6 4 12 21 16 20 13 12 9
9 4 6 -1 2 -4 0 1 6 -2
8 7 1 2 9 4 6 2 -1
2 2 1
``````
Output

Code: Select all

``````Jolly
Jolly
Jolly
Jolly
``````

raj
Learning poster
Posts: 78
Joined: Fri Feb 15, 2013 5:39 pm

### Re: 10038 - Jolly Jumpers

SIR IF U HAVE TIME THEN PLEASE CAN U KINDLY EXPLAIN........HOW THE OUTPUTS CAME FROM INPUTS...........

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

### Re: 10038 - Jolly Jumpers

raj wrote:SIR IF U HAVE TIME THEN PLEASE CAN U KINDLY EXPLAIN........HOW THE OUTPUTS CAME FROM INPUTS.........
Take your time to read the problem statement carefully. I think it has a very good, clear explanation.

Now, just to illustrate it with an example, let's consider this test case:

Code: Select all

``````8 7 1 2 9 4 6 2 -1
``````
This can be read as: there is a sequence of 8 numbers, which are { 7, 1, 2, 9, 4, 6, 2, -1 }. Now, consider all pairs of consecutive numbers in this sequence: the first pair is (7, 1). The absolute value of their difference is 6. The second pair is (1, 2), and the abs of the difference is 1, etc. If you continue like this, you produce a second sequence of 7 numbers, which would be:

Code: Select all

``````new sequence      ->    6   1   7   5   2   4   3
original sequence ->  7   1   2   9   4   6   2  -1
``````
As you can see, the new sequence is formed by all the integer numbers between 1 and 7. Hence, it's a jolly jumper.

As a general advice, I suggest that you put a little more effort at the moment of reading the problems. I know sometimes problem statements can be confusing, especially if English is not your first language, but being patient and reading the problems as many times as necessary until you're fully confident that you understand everything that is being said is crucial, and if you consciously work on improving this skill, it helps you speed up your progress tremendously.

raj
Learning poster
Posts: 78
Joined: Fri Feb 15, 2013 5:39 pm

### Re: 10038 - Jolly Jumpers

Code: Select all

``````accepted
``````
Last edited by raj on Mon Mar 11, 2013 2:14 am, edited 1 time in total.

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

### Re: 10038 - Jolly Jumpers

sir i saw all the inputs that u wrote and including various inputs and all of them are correct.........
but the online judge says it wrong answer ?? please kindly see my code
It seems that you're still misunderstanding the problem.

Check for example this case:

Code: Select all

``````5 1 2 3 4 5
``````

Code: Select all

``````Not jolly
``````
As you can see, the sequence is (1, 2, 3, 4, 5) and the absolute value of the differences of consecutive elements are (1, 1, 1, 1), but to be a jolly jumper, they should be a permutation of (1, 2, 3, 4).

raj
Learning poster
Posts: 78
Joined: Fri Feb 15, 2013 5:39 pm

### Re: 10038 - Jolly Jumpers

THANKS SIR........ now its accepted..........

yes sir your guess is 1000 % right maximum time i misunderstood / hardly understand problems besides English is mine 2nd language.......

can u sir please give me any extraordinary advice how to overcome it.........

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

### Re: 10038 - Jolly Jumpers

raj wrote: can u sir please give me any extraordinary advice how to overcome it.........
I don't think I'm very good at giving advice (I try), but I'd say for now just focus on improving your reading comprehension, and work on your patience and general attitude towards problem solving as well.

A couple of tips I can think of:
• Make a conscious effort to avoid writing any code until you're completely sure that you understand everything in the problem statement. There will be times when, in the middle of reading a problem for the first time, you think you have the gist of it and may think you can predict the rest of the details and you can just start writing code right away. Don't do it. Always read the full problem statement, and all the important details at least twice. If you still don't understand something, even if it's something that looks like a "small", insignificant detail, keep reading until you are 100% sure you have a clear picture of what the problem is asking for. Then try to work out the problem in your head first, or use pencil and paper, until you have formulated a strategy to solve the problem. And then, only then, start writing code.
• Spend more time reading things in English. It could be anything you want; books, newspapers, blogs, comics, etc. Keep in mind that using translation tools and dictionaries is very useful to some degree, but there are things in "informal writing" (idioms, common expressions, peculiar grammar conventions) that you can't easily learn any other way other than just reading real things written by real people.
If you persevere, then there will be no boundaries to how much you can learn and improve... Don't worry if it feels it's too difficult sometimes, it will get easier with time, just don't give up .

Good luck.

raj
Learning poster
Posts: 78
Joined: Fri Feb 15, 2013 5:39 pm

### Re: 10038 - Jolly Jumpers

THANKS SIR.......

Munchor
New poster
Posts: 19
Joined: Sun Mar 03, 2013 4:03 pm

### Re: 10038 - Jolly Jumpers

gr81 wrote:0
4 1 2 3 4
4 1 4 2 3
5 1 4 2 -1 6
10 1 2 3 4 5 6 7 8 9 10
10 1 2 4 7 11 16 22 29 37 46
10 -1 -2 -4 -7 -11 -16 -22 -29 -37 -46
10 -1 -1 -4 -7 -11 -16 -22 -29 -37 -46
1 1
2 1 2
2 2 1
4 0 4 2 3
4 1 3 2 4
1 2
6 1 4 3 7 5 10
1 1
5 3 4 2 3 5
1 10
4 1 4 2 3
5 1 4 2 -1 6
6 3 2 4 3 2 1
1 4
0
4 2342342234234234 34234235434534554 67574523423 23425346546546546546
9 10 5 1 4 6 12 19 27 26
4 1 4 2 3
5 1 4 2 -1 6
6 3 2 4 3 2 1
4 1 3 0 -1
4 1 3 2 -2
1 2000
2 1999 1998
3 1 2 4
3 4 2 1
3 104 102 101
3 -5 -7 -6
3 4 1 3
200 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
10 1 2 3 4 5 6 7 8 9 10
10 1 2 4 7 11 16 22 29 37 46
10 -1 -2 -4 -7 -11 -16 -22 -29 -37 -46
10 -1 -1 -4 -7 -11 -16 -22 -29 -37 -46
1 1
2 1 2
2 2 1
4 0 4 2 3
4 1 3 2 4
1 2
6 1 4 3 7 5 10
5 3 4 2 3 5
9 5 6 4 1 -3 2 8 15 7
9 10 5 1 4 6 12 19 27 36
9 10 5 1 4 6 12 19 27 26
2 0 257
2 1 4000
I'd very much appreciate some AC output on that. I know I can use (http://www.uvatoolkit.com/problemssolve.php) but it doesn't work for this large input and it says "0 4 2 3" is a jolly jumper for n=4, which I don't think is right.

Anyways, I'm getting a runtime error (which might be because I'm accessing an index that is not in the array, but I have checks for >3000, so I don't know how the RE could be happening), does anybody have any idea? problemsolve.php also says "1 3 2 4" is a jolly jumper for n = 4, but once again I don't think it is and so does my program. I think the tool may not be working correctly.

Code: Select all

``````#include <stdio.h>
#include <math.h>
#include <string.h>

int main()
{
int n, i, x, is_jolly, sequence[3010], diff[1600];

while (scanf("%d", &n) != EOF)
{
memset(sequence, 0, sizeof sequence);
memset(diff, 0, sizeof diff);
is_jolly = 1;

for (i = 0; i < n; i++)
{
scanf("%d", &x);
sequence[i] = x;
}

for (i = 0; i < n - 1; i++)
{
if (abs(sequence[i] - sequence[i + 1]) > 3000)
continue;

diff[abs(sequence[i] - sequence[i + 1])] = 1;
}

for (i = 1; i < n - 1; i++)
{
if (!diff[i])
{
is_jolly = 0;
break;
}
}

if (is_jolly)
{
printf("Jolly\n");
}
else
{
printf("Not jolly\n");
}
}

return 0;
}
``````

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

### Re: 10038 - Jolly Jumpers

Munchor wrote: (..)I'd very much appreciate some AC output on that. I know I can use (http://www.uvatoolkit.com/problemssolve.php) but it doesn't work for this large input and it says "0 4 2 3" is a jolly jumper for n=4, which I don't think is right.

Anyways, I'm getting a runtime error (which might be because I'm accessing an index that is not in the array, but I have checks for >3000, so I don't know how the RE could be happening), does anybody have any idea? problemsolve.php also says "1 3 2 4" is a jolly jumper for n = 4, but once again I don't think it is and so does my program. I think the tool may not be working correctly.
There might be something strange in the way you access uvatoolkit. I just went and tried the following input:

Code: Select all

``````4 0 4 2 3
4 1 3 2 4
``````

Code: Select all

``````Not jolly
Not jolly
``````
About the set of inputs you reposted, I see it includes some integers that are larger than 2^31-1, so that could be tripping up the uvatoolkit program. In my code I assume all integers fit in a signed 32-bit integer, and it worked okay.

I also think test cases with n=0 are not present in the input because uvatoolkit and my program produce different results for that. Anyway, finding the answers manually for the rest of the cases shouldn't be too hard.

Also, try these cases:

Input

Code: Select all

``````2 4 -4
2 4 2
``````
Output

Code: Select all

``````Not jolly
Not jolly
``````

hello
New poster
Posts: 25
Joined: Sun Mar 10, 2013 7:29 pm

### Re: 10038 - Jolly Jumpers

Code: Select all

``<Removed After Got accepted>``
Last edited by hello on Mon Mar 18, 2013 1:26 pm, edited 1 time in total.

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

### Re: 10038 - Jolly Jumpers

hello wrote: WhY WA......?.... I have tested so many inputs from here..... Can anyone give me some new.....
In my machine your program doesn't print the correct answers for the sample test cases, but you may see something different in your own system because there's a bug related to uninitialized positions of memory. Think about the behavior of this line of code:

Code: Select all

``````    sort(arr1,arr1+num);
``````
Keep in mind the number of elements that you place in the arr1 array.

hello
New poster
Posts: 25
Joined: Sun Mar 10, 2013 7:29 pm

### Re: 10038 - Jolly Jumpers

Thanks lbv for this support.that was really a small but big bug........

salmaeng94
New poster
Posts: 1
Joined: Thu Jun 27, 2013 5:19 pm

### Re: 10038 - Jolly Jumpers

hello i have tried all your test cases and i they all true but i still have wA can any one help ?pleaze
my code is
#include <iostream>
#include<stdio.h>
#include<string.h>
#include <math.h>
#include <stdlib.h>
#include <cstdlib>
using namespace std;
int main ()

{ int n;

while((cin>>n)&&n>0)
{

bool joly=true;
int x,y,num;
int z=0;
num=n;
int diff[3010]={0};
cin>>y;

while(n>1)
{
cin>>x;
if((diff[abs(y-x)]==0)&&(abs(y-x)<num)&&(abs(y-x)!=0))
{
diff[abs(y-x)]=1;
y=x;
}

else {
joly=false;
break;
}
n--;
}
if(joly)
{
for(int i=1; i<num;i++)
{
if (diff==0)
{
joly=false; break;
}
}

}
if (joly) cout<<"Jolly"<<endl;
else cout<<"Not jolly"<<endl;
cin.ignore(256,'\n');
}
return 0;

}