10038 - Jolly Jumpers
Moderator: Board moderators
Code: Select all
code remove
i have try the input on borad , still cannot find out what's wrong.
i need some helps , thanks

Last edited by toni on Thu Aug 30, 2007 4:59 am, edited 1 time in total.
Your code doesn't even pass the samples. Check the spelling please.
Ami ekhono shopno dekhi...
HomePage
HomePage
I think this is so simple but still got WA...
I passed all tests in the board
Can anyone help me to find what is wrong here...
Code: Select all
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
int n, truoc, sau, co[3010];
while (1)
{
cin >> n;
if (cin.eof()) break;
memset(&co, false, sizeof(co));
cin >> truoc;
for (int i=1; i<n; i++)
{
cin >> sau;
int khac=fabs(sau-truoc);
if (1<=khac && khac<=n-1)
co[khac]=true;
truoc=sau;
}
bool jolly=true;
for (int i=1; i<n; i++)
if (!co[i])
{
//cout << "false " << i << endl;
jolly=false;
break;
}
if (jolly)
cout << "Jolly" << endl;
else
cout << "Not jolly" << endl;
}
return 0;
}
Can anyone help me to find what is wrong here...
Same problem - time limit exceeded
I'm having the same problem. Does anyone know why? I suspect its because some loop or other isn't terminating...
Code: Select all
/*
* $Header: /home/kundai/src/working/RCS/jolly.c,v 1.7 2007/09/09 07:13:22 kundai Exp kundai $
*/
#include <stdio.h>
#include <stdlib.h>
int abs(int x){
if(x<0)
return -x;
return x;
}
int
main(){
unsigned int c;
int N=0, n=0; /*loop counter*/
char jolly;
int i, d;
int vals[2];
char* diffs; /*for set*/
while(scanf("%d",&N)!=EOF){
diffs=calloc(N,sizeof(*diffs));
#if !defined(ONLINE_JUDGE)
if(!diffs){
fputs("Could not allocate the diffs buffer. Sorry.\n",stderr);
return 1;
}
#endif
jolly=1;
i=0;
n=N;
while(n>0){
--n;
scanf("%d",&c);
vals[i%2]=c;
++i;
/*testing sequence*/
if(i>1){
d=abs(vals[0]-vals[1]);
if(d<1 || d>(N-1)){ /*check for invalid difference*/
jolly=0;
}else{
if(d>0 && d<N){ /*check for collisions*/
if(diffs[d])
jolly=0;
diffs[d]++; /*update diffs buffer*/
}
}
}
#if defined(DEBUG)
/*debug*/
fprintf(stderr,"%d ",c);
#endif
}
if(jolly){
printf("Jolly\n");
}else{
printf("Not jolly\n");
}
#if defined(DEBUG)
fputc('\n',stderr);
#endif
free(diffs);
}
}
Heh. I must be the only one still using ANSI C.
I've tested the sample input data through my program, and gotten what appear to be the correct results, but I still get WA.
Any help would be appreciated
Forgive my lack of comments. // isn't supported by ANSI standard, and the whole /* */ shebang is too much to do quickly.
I've tested the sample input data through my program, and gotten what appear to be the correct results, but I still get WA.
Any help would be appreciated

Code: Select all
#include <stdio.h>
#define mabsdif(a,b) a-b>0?a-b:b-a
#define DEBUG 0
int main (void) {
char jj[3000];
int prev, d, i, isJolly, jjmax, c;
while (scanf("%d",&jjmax) != EOF) {
scanf("%d",&prev);
isJolly = 1;
for (i = 1; i < jjmax; i++) jj[i] = 0;
for (i = 1; i < jjmax; i++) {
scanf("%d",&d);
jj[mabsdif(d,prev)] = 1;
if (DEBUG) printf("%d ",mabsdif(d,prev));
prev = d;
}
for (i = 1; i < jjmax; i++) {
if (!jj[i]) {
isJolly = 0;
break;
}
}
printf(isJolly?"Jolly\n":"Not Jolly\n");
}
}
-
- New poster
- Posts: 6
- Joined: Sun Sep 09, 2007 3:56 pm
Look for your spelling, "Not Jolly" must be "Not jolly", maybe it helps,
Im getting WA on this problem too.
anyone can help please?!
Im getting WA on this problem too.
Code: Select all
// JollyJumpers.cpp : Defines the entry point for the console application.
// UVA 10038
#include <iostream>
#include <string>
using namespace std;
int main()
{
bool checked[3002];
bool error = false;
int number;
int counter = 0;
cin >> number;
while (true) {
error = false;
int first, second, dif;
string temp;
cin >> first;
for (int i = 0; i < number - 1; i++) {
cin >> second;
dif = abs(second - first);
if (dif < 1 || dif >= number || !checked[dif]) {
getline(cin, temp); // to skip whole line
cout << "Not jolly\n";
error = true;
break;
} else {
checked[dif] = false;
}
first = second;
}
if (!error)
cout << "Jolly\n";
if (!(cin >> number))
break;
for (int i = 0; i < number; i++) { // making the array like it was before
checked[i] = true;
}
}
return 0;
}
please help - getting WA for jolly jumpers
I tested my code with all the given sample inputs and the inputs in the board.
But, the judge gives me "Wrong Answer".
Here is my code.
Please help me and thanks in advance.
But, the judge gives me "Wrong Answer".
Here is my code.
Code: Select all
#include<iostream>
#include<vector>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
int n;
while( cin >> n )
{
int v[n];
for( int i = 0; i < n ; i++ )
{
cin >> v[i];
}
int b[n];
adjacent_difference( v, v + n, b );
for( int i = 0; i < n; i++ )
b[i] = abs( b[i] );
int c[n];
c[0] = 1;
for( int i = 1; i < n; i++ )
c[b[i]] = 1;
if( accumulate( c, c + n, 0 ) == n )
printf( "Jolly\n" );
else
printf( "Not jolly\n" );
}
return 0;
}
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Rajesh V,
initialize your array
initialize your array
Code: Select all
int c[n];
c[0] = 1;
for(int i=1;i<n;++i)c[i]=0;
Re: 10038 - Jolly Jumpers
how do i read the input. does it continue endlessly? please just post the reading the input section.
-
- New poster
- Posts: 4
- Joined: Fri May 23, 2008 6:55 am
- Location: Dhaka
- Contact:
Re: 10038 - Jolly Jumpers
To daichin85,
You should read the input such a way that the differences between adjacent numbers must cover all the numbers from 1 to n-1.
Good luck!!!!!!!!!!!!
You should read the input such a way that the differences between adjacent numbers must cover all the numbers from 1 to n-1.
Good luck!!!!!!!!!!!!
Sopno dhaka mon akash choar.............
Re: 10038 - Jolly Jumpers
See Rajesh V's code or Hikaru78's code..daichin85 wrote:how do i read the input. does it continue endlessly? please just post the reading the input section.

10038 Jolly Jumbers (Run time error)
Hi every one.
Every time I submit my code i get this error:
And this this is my code:
Every time I submit my code i get this error:
Although it runs correctly.Your submission with number 6533032 for the problem 10038 - Jolly Jumpers has failed with verdict Runtime error.
This means that the execution of your program didn't finish properly. Remember to always terminate your code with the exit code 0.
And this this is my code:
Code: Select all
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package jollyjumpers;
import java.util.Scanner;
/**
*
* @author Galileo
*/
public class Main {
// Jolly Jumpers (Jolly or Not Jolly)
static int Jolly(int a[])
{
int[] result = new int[a.length - 2];
int tmp = 0;
for(int i = 1; i < a.length - 1; i++)
{
result[i - 1] = Math.abs(a[ i ]-a[i + 1] );
}
int step = Math.abs(result[0] - result[1]);
int direction = -1;
if(result[0] > result[1])
direction = 0;
else
direction = 1;
for(int i = 0; i < a.length - 3; i++)
{
if(direction == 0)
{
tmp = result[i+1] + step;
if(result[i] != tmp)
return 1;
}
else
{
tmp = result[i+1] - step;
if(result[i] != tmp)
return 1;
}
}
return 0;
}
static int[] StringSplit(String s)
{
String[] str = new String[s.length()];
str = s.split(" ");
int[] a = new int[str.length];
for(int i = 0; i < str.length; i++)
{
a[i] = Integer.parseInt(str[i]);
}
return a;
}
public static int main(String[] args)
{
Scanner scanner = new Scanner(System.in);
String[] s = new String[1024];
String[] tmps = new String[1024];
String str = "" , tmpstr = "";
int setscount = 0;
//System.out.println("Type your data sets or 0 to end input process\n");
while(true)
{
str = scanner.nextLine();
System.out.println();
if(str.equals("0"))
break;
tmps = str.split(" ");
if(tmps[0].equals("1") || tmps[0].equals("2"))
s[setscount] = "J";
else
{
if(tmpstr.length() < 3001)
{
s[setscount] = str;
}
else
s[setscount] = "I";
}
setscount++;
}
for(int i = 0; i < setscount; i++)
{
if(s[i].equals("I"))
System.out.println("Invalid Input\n");
else
{
if(s[i].equals("J"))
System.out.println("Jolly\n");
else
{
if(Jolly(StringSplit(s[i])) == 0)
System.out.println("Jolly\n");
else
System.out.println("Not jolly\n");
}
}
}
return 0;
}
}