## 10038 - Jolly Jumpers

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

godsont
New poster
Posts: 2
Joined: Sun Mar 30, 2014 2:55 pm

### 10038 - Jolly Jumpers WA

Hi, I'm new to this site. I have tried solving the problem called Jolly Jumpers but got a Wrong Answer. I have tried a couple of times. Please help me find the error in the code below. I have tested with the input example in the problem and got the output right.

Code: Select all

``````#include <iostream>
#include <stdlib.h>
using namespace std;

int main(){
int n, input[3000], difference[3000], status=0, temp;
while(cin>>n){
if(n>1 || n<3000){
for(int i=0; i<n; i++){
cin>>input[i];
}
for(int i=0; i<n-1; i++){
difference[i] = abs(input[i] - input[i+1]);
}

// sort

for(int i = 0; i<n-1; i++){
for(int j = 0; j<i; j++){
if(difference[i] < difference[j]){
temp = difference[j];
difference[j] = difference[i];
difference[i] = temp;
}
}
}

for(int i = 0; i<n-1; i++){
if(difference[i] != i+1){
status = 0;
}
else{
status = 1;
}
}

if(status == 0){
cout<<"Not jolly"<<endl;
}
else {
cout<<"Jolly"<<endl;
}
}
}
return 0;
}

``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10038 - Jolly Jumpers WA

4 1 2 3 6 is Not jolly
Check input and AC output for thousands of problems on uDebug!

mhsn06
New poster
Posts: 16
Joined: Tue Apr 01, 2014 7:36 pm

### 10038 Jolly Jumpers Code works but return WA

Code: Select all

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

int main()
{
int n;
while(scanf("%d", &n) == 1)
{
int y=0, s=0, isFirst=1, i;
for(i=0; i<n; i++)
{
int temp=y;
scanf("%d", &y);
if(isFirst)
{
isFirst = 0;
continue;
}
s += abs(temp-y);
}

if(s==((i*(i-1))/2))
{
printf("Jolly\n");
}
else
{
printf("Not jolly\n");
}
}
return 0;
}``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10038 Jolly Jumpers Code works but return WA

4 1 7 7 7 is not jolly
Check input and AC output for thousands of problems on uDebug!

godsont
New poster
Posts: 2
Joined: Sun Mar 30, 2014 2:55 pm

### Re: 10038 - Jolly Jumpers WA

hi brianfry713, I have made a change in the program and now the sequence you provided is providing correct output. Please have a look at what else is the error in the program.

Here's the edited code:

Code: Select all

``````#include <iostream>
#include <stdlib.h>
using namespace std;

int main(){
int n, input[3000], difference[3000], status=0, temp;
while(cin>>n){
if(n>1 || n<3000){
for(int i=0; i<n; i++){
cin>>input[i];
}
for(int i=0; i<n-1; i++){
difference[i] = abs(input[i] - input[i+1]);
}

// sort

for(int i = 0; i<n-1; i++){
for(int j = 0; j<i; j++){
if(difference[i] < difference[j]){
temp = difference[j];
difference[j] = difference[i];
difference[i] = temp;
}
}
}

for(int i = 0; i<n-1; i++){
if(difference[i] != i+1){
status = 0;
break;
}
else{
status = 1;
}
}

if(status == 0){
cout<<"Not jolly"<<endl;
}
else {
cout<<"Jolly"<<endl;
}
}
}
return 0;
}
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10038 - Jolly Jumpers WA

The definition implies that any sequence of a single integer is a jolly jumper.
Input:

Code: Select all

``````2 1 3
1 1
``````
Correct output:

Code: Select all

``````Not jolly
Jolly
``````
Check input and AC output for thousands of problems on uDebug!

b1gm4f14
New poster
Posts: 3
Joined: Fri Apr 11, 2014 9:08 pm

### 10038 why getting WA

#include<stdio.h>
#include<math.h>
int main()
{
int a[3000],b[3000],i,j,t,s;
scanf("%d",&t);
for(i=1;i<=t;i++)
scanf("%d",&a);
for(i=1;i<t;i++)
{
b=abs(a-a[i+1]);
}
if(b[1]>b[2])
{
for(j=1;j<t-1;j++)
{
if(b[j]-1!=b[j+1])
{
printf("Not jolly\n");
break;
}
if(j==(t-2))
printf("Jolly\n");
}
}
if(b[1]<b[2])
{
for(j=1;j<t-1;j++)
{
if(b[j]+1!=b[j+1])
{
printf("Not jolly\n");
break;
}
if(j==(t-2))
printf("Jolly\n");
}
}
return 0;

}

b1gm4f14
New poster
Posts: 3
Joined: Fri Apr 11, 2014 9:08 pm

### 10038 why getting WA

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
int a[3010],b[3010],c[3001],i,j,t,s,k;
scanf("%d",&t);
for(i=1;i<=t;i++)
scanf("%d",&a);
for(i=1;i<t;i++)
{
s=abs(a[i+1]-a);
b[s]=1;
}
for(i=1;i<t;i++)
{
if(b==0||b>=t)
{
printf("Not jolly\n");
break;
}
if(i==t-1)
printf("Jolly\n");
}
return 0;

}

ultima_key
New poster
Posts: 10
Joined: Tue Mar 25, 2014 12:50 pm

### Re: 10038 - Jolly Jumpers

Code: Select all

``````#include <bits/stdc++.h>
#define ll long long int
using namespace std;

inline void fastRead_int(ll &x) {
register ll c = getchar();
x = 0;
ll neg = 0;
for(; ((c<48 || c>57) && c != '-'); c = getchar());
if(c=='-') {
neg = 1;
c = getchar();
}
for(; c>47 && c<58 ; c = getchar()) {
x = (x<<1) + (x<<3) + c - 48;
}
if(neg)
x = -x;
}

int main(){
int c;
while(cin >> c){
if(!c) break;
ll jo[c];
for(int i = 0; i < c; i++) fastRead_int(jo[i]);
bool jolly = true;
map<int, ll> l;
for(int i = 0; i < c-1; i++){
if(abs(jo[i] - jo[i+1]) < c){
if(l[abs(jo[i] - jo[i+1])] == 0) l[abs(jo[i] - jo[i+1])]++;
else{
jolly = false;
break;
}
}
}
if(jolly) cout << "Jolly" << endl;
else cout << "Not jolly" << endl;
}
}
``````
I don't know what is wrong with my code because it gives the correct output but still gets a WA Verdict. Can someone please help me?

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10038 -Jolly jumper. getting WA

Don't double post
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10038 why getting WA

You need to keep reading test cases until the end of file.
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10038 - Jolly Jumpers

2 1 1 is Not jolly
Check input and AC output for thousands of problems on uDebug!

refatsardar
New poster
Posts: 6
Joined: Sat Jun 07, 2014 10:22 pm

### Re: 10038 - Jolly Jumpers WA

Could you please tell me why 1 1 or 1 2 is a jolly.Since it has only one element so that we will not find any difference,then how to check this condition "the absolute values of the difference between successive elements take on all the values 1 through n-1".
I don't understand this things for 1 1 is a jolly.

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

### Re: 10038 - Jolly Jumpers WA

refatsardar wrote:Could you please tell me why 1 1 or 1 2 is a jolly. (..)
As the problem statement specifies, a sequence of n integers is a jolly jumper if:
• n > 0
• The set of integers formed by the absolute differences of successive elements is the same set as the integers { 1, 2, ..., (n-1) }
As you say, a sequence with n=1 has no successive elements, so that set is empty. On the other hand, the set { 1, ..., 0 } is also empty. Therefore, all the conditions are satisfied, and a sequence with n=1 is always jolly.

refatsardar
New poster
Posts: 6
Joined: Sat Jun 07, 2014 10:22 pm

### Re: 10038 - Jolly Jumpers WA

Thnaks lbv,got it your point.