10038 - Jolly Jumpers
Moderator: Board moderators
Re: 10038 - Jolly Jumpers
Thank you for your reply.
That was not my problem. My actual problem is:
For my 1st input: 4 1 4 2 3 the output screen show me that it is Jolly and for the 2nd input: 5 1 4 2 -1 6 the output screen show me that it is Not jolly. Both two test inputs are ok. But my problem occurs from the 3rd test case. For my 3rd input: 4 1 4 2 3 the output screen show me that it is Not jolly but it is a Jolly. What is the problem? Why the error occur?
That was not my problem. My actual problem is:
For my 1st input: 4 1 4 2 3 the output screen show me that it is Jolly and for the 2nd input: 5 1 4 2 -1 6 the output screen show me that it is Not jolly. Both two test inputs are ok. But my problem occurs from the 3rd test case. For my 3rd input: 4 1 4 2 3 the output screen show me that it is Not jolly but it is a Jolly. What is the problem? Why the error occur?
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
On line 18 you set up to c[n-1], but on line 22 you check up to c[n], so that's why you see a difference. Also your algorithm won't work for a case like: 3 1 2 4, output should be Jolly.
Check input and AC output for thousands of problems on uDebug!
Re: 10038 - Jolly Jumpers
Thank you for your reply. I just need to check my code.
-
- New poster
- Posts: 1
- Joined: Wed Oct 24, 2012 10:28 am
Re: 10038 - Jolly Jumpers
This main problem is that the absolute values may not be order. for example, 1,2,3 is ok, 2, 3,1 is ok,too.
Re: 10038 - Jolly Jumpers
Can anyone provide me some sample input and sample output of Jolly Jumpers?
Re: 10038 - Jolly Jumpers
What's wrong in my code? Got WA!!
Code: Select all
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
int n, i, count, j;
int a[3002], c[3002];
while(cin>>n)
{
for(i = 1; i <= n; i++)
{
cin>>a[i];
}
for(i = 1; i <= n-1; i++)
{
c[i] = abs(a[i] - a[i+1]);
}
for(i = 1; i <= n-1; i++)
{
for(j = i + 1; j <= n-1; j++)
{
count = 0;
if(abs(c[i] - c[j]) == 1)
{
count = 1;
}
}
}
if(count == 1)
{
printf("%s\n", "Jolly");
}
else
{
printf("%s\n", "Not jolly");
}
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
3 1 3 6 is Not jolly
Check input and AC output for thousands of problems on uDebug!
Re: 10038 - Jolly Jumpers
Can anyone tell me what's wrong now? Still got WA!!!!

Code: Select all
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
int n, i, count, j;
int a[3002], c[3002];
while(cin>>n)
{
for(i = 1; i <= n; i++)
{
cin>>a[i];
}
for(i = 1; i <= n-1; i++)
{
c[i] = abs(a[i] - a[i+1]);
}
for(i = 1; i <= n-1; i++)
{
for(j = i + 1; j <= n-1; j++)
{
count = 0;
if(c[1] == 1 || c[n-1] == 1)
{
if(abs(c[i] - c[j]) == 1)
{
count = 1;
}
}
else
{
count = 0;
}
}
}
if(count == 1)
{
printf("%s\n", "Jolly");
}
else
{
printf("%s\n", "Not jolly");
}
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
5 1 4 1 3 2 is Not jolly.
See http://acm.uva.es/board/viewtopic.php?t=16018
See http://acm.uva.es/board/viewtopic.php?t=16018
Check input and AC output for thousands of problems on uDebug!
Re: 10038 - Jolly Jumpers
I struggled A LOT with this problem.
The problem specification is misleading.
The problem reads:
"Each line of input contains an integer n < 3, 000 followed by n integers representing the sequence."
But there are test cases where n == 3000.
No wonder why the authors said "use arrays larger than what you really need". I thought this was because they assumed we were sloppy coders. I didn't have in mind THEY could be sloppy as well.
The problem specification is misleading.
The problem reads:
"Each line of input contains an integer n < 3, 000 followed by n integers representing the sequence."
But there are test cases where n == 3000.
No wonder why the authors said "use arrays larger than what you really need". I thought this was because they assumed we were sloppy coders. I didn't have in mind THEY could be sloppy as well.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
The problem statement has n<=3000
Check input and AC output for thousands of problems on uDebug!
Re: 10038 - Jolly Jumpers
hello, I need some help here, I dunno where's the mistake of my code, i keep getting WA.
pls help
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long long arr[3001];
int n;
while(scanf("%d",&n)!=EOF)
{
bool jolly=true;
bool used[3001];
for(int i=0;i<n;i++)
{
used=false;
}
for(int i=0;i<n;i++)
{
scanf("%lld",&arr);
if(i>0)
{
long long diff=abs(arr-arr[i-1]);
if (diff<n) used[diff]=true;
}
}
if(n<=1) printf("Not jolly\n");
else
{
for(int i=1;i<n;i++) if(not used) jolly=false;
if(jolly) printf("Jolly\n");
else printf("Not jolly\n");
}
}
return 0;
}
pls help

#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long long arr[3001];
int n;
while(scanf("%d",&n)!=EOF)
{
bool jolly=true;
bool used[3001];
for(int i=0;i<n;i++)
{
used=false;
}
for(int i=0;i<n;i++)
{
scanf("%lld",&arr);
if(i>0)
{
long long diff=abs(arr-arr[i-1]);
if (diff<n) used[diff]=true;
}
}
if(n<=1) printf("Not jolly\n");
else
{
for(int i=1;i<n;i++) if(not used) jolly=false;
if(jolly) printf("Jolly\n");
else printf("Not jolly\n");
}
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
input:
1 1
AC output:
Jolly
1 1
AC output:
Jolly
Check input and AC output for thousands of problems on uDebug!
Re: 10038 - Jolly Jumpers
CAN ANYONE PLEASE TELL ME WHERE IS THE PROBLEM???
ONLINE JUDGE SAYS ITS WRONG ANSWER..............
import java.io.*;
import java.util.*;
public class Main{
public static void main(String [] args){
Scanner k = new Scanner(System.in);
while(true)
{
String s = k.nextLine();
int space = 0,c = 0;
for(c = 0;c<s.length();c++)
{
if(s.charAt(c)==' ')
{
space++;
}
}
Scanner b = new Scanner(s);
int [] v = new int [s.length()-space];
c = 0;
while(b.hasNextInt())
{
int i = b.nextInt();
v[c] = i;
c++;
}
int p = 1,chq = 0,save = 0,save1 = 0;
for(int t =0;t<v.length;t++)
{
if(!(v[t]>0))
{
chq = 1;
break;
}
}
while(p<v.length)
{
int max=0,min=0;
if(v[p-1]>v[p])
{
max = v[p-1];
min = v[p];
}
else
{
max = v[p];
min = v[p-1];
}
if(p==1)
{
save = max - min;
p++;
}
else
{
save1 = save;
save = max - min;
if((save==save1)||(save == (save1-1)))
{
p++;
}
else
{
chq = 1;
break;
}
}
}
if(chq == 0)
{
System.out.println("Jolly");
}
else
{
System.out.println("Not jolly");
}
}
}
}
ONLINE JUDGE SAYS ITS WRONG ANSWER..............

import java.io.*;
import java.util.*;
public class Main{
public static void main(String [] args){
Scanner k = new Scanner(System.in);
while(true)
{
String s = k.nextLine();
int space = 0,c = 0;
for(c = 0;c<s.length();c++)
{
if(s.charAt(c)==' ')
{
space++;
}
}
Scanner b = new Scanner(s);
int [] v = new int [s.length()-space];
c = 0;
while(b.hasNextInt())
{
int i = b.nextInt();
v[c] = i;
c++;
}
int p = 1,chq = 0,save = 0,save1 = 0;
for(int t =0;t<v.length;t++)
{
if(!(v[t]>0))
{
chq = 1;
break;
}
}
while(p<v.length)
{
int max=0,min=0;
if(v[p-1]>v[p])
{
max = v[p-1];
min = v[p];
}
else
{
max = v[p];
min = v[p-1];
}
if(p==1)
{
save = max - min;
p++;
}
else
{
save1 = save;
save = max - min;
if((save==save1)||(save == (save1-1)))
{
p++;
}
else
{
chq = 1;
break;
}
}
}
if(chq == 0)
{
System.out.println("Jolly");
}
else
{
System.out.println("Not jolly");
}
}
}
}
Re: 10038 - Jolly Jumpers
Was the verdict "Wrong Answer" or "Runtime Error"?raj wrote:CAN ANYONE PLEASE TELL ME WHERE IS THE PROBLEM???
ONLINE JUDGE SAYS ITS WRONG ANSWER..............![]()
For now, I can see that your code throws a java.util.NoSuchElementException exception when it reaches the end of the input. Try changing this:
Code: Select all
while(true)
{
String s = k.nextLine();
// etc.
}
Code: Select all
while(k.hasNextLine())
{
String s = k.nextLine();
// etc.
}