## 10038 - Jolly Jumpers

Moderator: Board moderators

bongssi
New poster
Posts: 14
Joined: Mon Jul 31, 2006 10:35 am

### Thanks Daveon,, but

Yes, my code says 1 is jolly but still got wrong answer... I don't know what to do... falling in panic...
Ah, if you can, it is very kind of you to give some test cases...

anik
New poster
Posts: 4
Joined: Mon Aug 28, 2006 9:10 pm
I am getting wa for this prb-10038 can any one say where is the prb??
Last edited by anik on Thu Nov 16, 2006 6:31 pm, edited 1 time in total.

anik
New poster
Posts: 4
Joined: Mon Aug 28, 2006 9:10 pm
I got acc !! i was using math.h 's abs function.i created a function and got acc!!

New poster
Posts: 3
Joined: Tue Jan 09, 2007 1:41 pm

### 10038always WA!!

well, this is killing me...
plz help me with this

Code: Select all

``````#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int n, i, ans, found=1;
long num[3000]={0};
char selisih[3000];

scanf("%d", &n);

memset (selisih, 0, sizeof (char)*3000);
for(i=1;i<=n;i++)
{
scanf("%ld", &num[i]);
if(i==n)
break;
}

if(n==1)
found=1;
for(i=2;i<=n;i++)
{

ans=abs(num[i]-num[i-1]);

if ((ans < n) && (ans != 0))
{
if (selisih[ans] == 0)
selisih[ans] = 1;

else
found = 0;
}

else found = 0;
}

if(found==0)
printf("Not jolly\n");

else
printf("Jolly\n");

return 0;
}``````
i have tried many times but always get WA

Spykaj
New poster
Posts: 47
Joined: Sun May 21, 2006 12:13 pm
Use size of array 3001 instead of 3000 ;p

New poster
Posts: 3
Joined: Tue Jan 09, 2007 1:41 pm

### it doesn't work..

sorry still WA

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:
Input can contain multiple test cases, each on a separate line.
Your program should solve all of them, not just the first one like it currently does.

ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:

### 10038 why Time Limit Exceeded

Code is here tell me why it exceeded time limit??
#include<stdio.h>
#include<math.h>

**********Code Removed**************
Last edited by ranacse05 on Tue Apr 10, 2007 1:55 pm, edited 1 time in total.

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Code: Select all

``while(scanf("%d",&num)) ``
change the above line to

Code: Select all

``while(scanf("%d",&num) == 1) ``

Anversi
New poster
Posts: 2
Joined: Sun Apr 01, 2007 12:57 am

### 10038 Jolly Jumpers - WA - Need help please

Someone can help why my code gets WA?

Code: Select all

``````#include <iostream>
using namespace std;

int main(){
int n, num1, num2, trash;
bool bool1, bool2;

while(cin >> n){
bool1=false;
bool2=true;
if (n>1){
for(int i =0; i<(n-1); i++){
if (i==0){
cin >> num1 >> num2;
}
else{
num1=num2;
cin >> num2;
}
if(num1>num2){
if ((num1-num2)==(n-1)){
bool1=true;
}
else{
if((num1-num2)>(n-1))
bool2=false;
}
}

else{
if ((num2-num1)==(n-1)){
bool1=true;
}
else{
if((num2-num1)>(n-1)||((num2-num1)==0))
bool2=false;
}
}
}

if(bool2==false)
cout << "Not Jolly" << endl;
else{
if(bool1==true)
cout << "Jolly" << endl;
else
cout << "Not Jolly" << endl;
}
}
else{
if (n<=0)
return 0;

else{
cin >> trash;
cout << "Jolly" << endl;
}
}
}//end while
return 0;
}
``````

Anversi
New poster
Posts: 2
Joined: Sun Apr 01, 2007 12:57 am
i know that "Not Jolly" is wrong

Maybe there's a bug on UVa that don't accept solution without the bigarray[3000].

Help !

sfelixjr
New poster
Posts: 9
Joined: Wed Apr 25, 2007 3:29 pm
Location: Brazil
Contact:

I was trying to solve the Jolly Jumpers problem, but i got a wrong answer
here is my java code:

Code: Select all

``````import java.io.IOException;
import java.util.StringTokenizer;

class Main {
byte lin[] = new byte[maxLg];
int lg = 0, car = -1;

try {
while (lg < maxLg) {
if ((car < 0) || (car == '\n'))
break;
lin[lg++] += car;
}
} catch (IOException e) {
return (null);

}

if ((car < 0) && (lg == 0))
return (null);
return (new String(lin, 0, lg));
}

public static void main(String args[]) {

Main myWork = new Main();
myWork.begin();
}

void begin() {
while (true) {
StringTokenizer token = new StringTokenizer(input);
int n = Integer.parseInt(token.nextToken());
int[] v = new int[n];
for (int i = 0; i < n; i++)
v[i] = Integer.parseInt(token.nextToken());
resolve(n,v);
}
}
void resolve(int n, int[] v){
boolean condi = false;

boolean[] z = new boolean[n];
for (int i = 0; i < n; i++)
z[i] = false;
for (int i = 0; i < n-1; i++) {
int valor = Math.abs(v[i] - v[i + 1]);
if (valor >= n)
condi = false;
else if (valor -1 >= 0)
z[valor-1] = true;

}
if (condi)
System.out.println("Not jolly");
else {
boolean troca = true;
for(int i = 0; i < n-1; i++) {
if (z[i] == false){
troca = false;
break;
}
}
if (troca)
System.out.println("Jolly");
else
System.out.println("Not jolly");
}
}
}
``````
I' ve tried to this input:

Code: Select all

``````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
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
``````
and the result is...

Code: Select all

``````Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Jolly
Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Not jolly
``````
It's ok, isn't?
does anybody help me?
thanks

Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am
Contact:
hmmm some diff....check my output form my ac code...

Code: Select all

``````Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Jolly
Jolly
Not jolly
Not jolly
Not Jolly
Jolly
Not jolly
Jolly
Not jolly
Jolly
``````
may it help u....

GOOD LUCK
Rocky

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore
My AC program has a slightly different output than the one above.

My AC program outputs:

Code: Select all

``````Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Jolly
Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Not jolly
Jolly
``````
As for which one is correct, it all comes down to the following input:

Code: Select all

``````1 2
``````
Since there is only one integer, shouldn't the correct output be "Jolly"?

sfelixjr
New poster
Posts: 9
Joined: Wed Apr 25, 2007 3:29 pm
Location: Brazil
Contact:
``````1 2