## 10038 - Jolly Jumpers

Moderator: Board moderators

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

### Re: 10038 - Jolly Jumpers

Sharkest yes I think normally there is a newline following the last line. Ideally your code should work either way.
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

3sam 3 100 0 1 is Not jolly.
Check input and AC output for thousands of problems on uDebug!

3sam
New poster
Posts: 6
Joined: Mon Apr 09, 2012 8:33 pm

### Re: 10038 - Jolly Jumpers

brianfry713 wrote:3sam 3 100 0 1 is Not jolly.
i can`t understand you .......what must i do to get accepted ????? plz help

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

### Re: 10038 - Jolly Jumpers

Your code fails on the input I posted. Your algorithm is wrong. Read the problem again. A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-1. So you need to make sure your diff array contains all of those values. Right now you only check each one to see if it equals y or if it equals one of the next two.

Alguem
New poster
Posts: 1
Joined: Sun May 06, 2012 10:47 pm

### Re: 10038 - Jolly Jumpers

import java.io.*;
import java.util.*;

class JollyJumper {

public static void main(String[] args) {
JollyJumper myWork = new JollyJumper();
myWork.begin();
}

void jollyFunction(Set S,long n)
{
long i;

for(i=1;i<n;i++)
if(!S.contains(i))
{
System.out.println("Not jolly");
return;
}

System.out.println("Jolly");
}

void begin () {
String line;
long a,b,i,n;
Set S = new HashSet();
try{

while( true )
{
if(line==null)
break;

Scanner ins = new Scanner(line);

if(!ins.hasNextLong())
break;

n=ins.nextLong();

a=ins.nextLong();

for(i=2;i<=n;i++)
{
b=ins.nextLong();

a=b;
}

jollyFunction(S,n);
S.clear();
}

}

catch(Exception e)
{
e.printStackTrace();
}
}

}

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

### Re: 10038 - Jolly Jumpers

I think your RE is from a case where n=0.
Check input and AC output for thousands of problems on uDebug!

elmagnifico
New poster
Posts: 5
Joined: Mon Apr 30, 2012 10:15 am

### Re: 10038 - Jolly Jumpers

Code: Select all

``code removed after AC``
"Not Jolly" is actually "Not jolly".
5 WA then AC..

Mahbub9
New poster
Posts: 1
Joined: Tue Jun 26, 2012 7:16 pm

### 10038 - Jolly Jumpers

What's wrong with this code? I didn't find anything wrong. But I'm getting WA. Anyone please help me.

#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,jolly[3020],absolute_value,c,i;
while(scanf("%d",&n)==1)
{
c=1;
for(i=1;i<=n;i++)

scanf("%d",&jolly);
for(i=n;i>=2;i--)
{
if(abs(jolly-jolly[i-1])!=c)
{
printf("Not jolly\n");
break;
}
else c+=1;
}

if(c==n)
printf("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

Try the I/O posted in this thread: http://acm.uva.es/board/viewtopic.php?t=16018
Check input and AC output for thousands of problems on uDebug!

esharif
New poster
Posts: 18
Joined: Sun Jun 03, 2012 11:56 pm

### Why WA for 10038, help me plz..

Code: Select all

``````#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<stdio.h>
#include<stdlib.h>
#define N 3001

using namespace std;

long int a[N];

int main()
{
long int n, i, j, l, temp, dif, num, flag;
while(scanf("%ld",&n)==1)
{
flag=0;
l=0;
for(i=0;i<n;i++)
{
scanf("%ld", &num);
if(i!=0)
{
dif=abs(num-temp);
a[i-1]=dif;
}
temp=num;
}

if(n==1)
printf("Jolly\n");
else if(n==2)
{
temp=abs(a[0]-a[1]);
printf("temp is %ld \n", temp);
if(temp==0 || temp==1)
printf("Jolly\n");
else
printf("Not jolly\n");
}
else if(n>2)
{
if(a[1]>a[0])
for(i=0;i<n-2;i++)
{
if(a[i+1]==a[i]+1)
l++;
}
else if(a[1]<a[0])
for(i=0;i<n-2;i++)
{
if(a[i]==a[i+1]+1)
l++;
}
if(l!=n-2)
printf("Not jolly\n");
else if(l==n-2)
printf("Jolly\n");
}
}
return 0;
}
``````

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

### Re: Why WA for 10038, help me plz..

Try the I/O posted in this thread: http://acm.uva.es/board/viewtopic.php?t=16018
Check input and AC output for thousands of problems on uDebug!

sumit saha shawon
New poster
Posts: 19
Joined: Tue Jun 26, 2012 9:19 pm

### Re: 10038 - Jolly Jumpers

what is wrong with my algorithm:
#include<stdio.h>
#include<math.h>
int a[3050],k[3050];
int main()
{
int n,i,l,dif,y,j,temp;
while(scanf("%d",&n)==1)
{
y=0;
j=0;
// scanf("%d",&a[0]);
for(i=0;i<n;i++)
scanf("%d",&a);
for(i=0;i<n-1;i++)
{
temp=(a-a[i+1]);
if(temp<0)
temp=temp*(-1);
k[j]=temp;
j++;

}
for(i=0;i<j-1;i++)
{
dif=(k-k[i+1]);
if(dif<0)
dif=dif*(-1);
if(dif!=1)
{
y=1;
break;
}
}
if(y==1)
printf("Not jolly\n");
else
printf("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

4 1 4 3 5 is Jolly
Check input and AC output for thousands of problems on uDebug!

S4shuvro
New poster
Posts: 1
Joined: Mon Aug 13, 2012 1:10 pm

### Re: 10038 - Jolly Jumpers

how can 6 3 2 4 3 2 1 be jolly? can anyone please explain?

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

### Re: 10038 - Jolly Jumpers

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