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

Waddle
New poster
Posts: 22
Joined: Thu Jan 25, 2007 3:54 pm
Location: Taiwan
Contact:

Post by Waddle »

Oh~I got it.
Thank you!!!

comaniac
New poster
Posts: 2
Joined: Sun Jul 22, 2007 7:24 pm
Location: Taiwan,Taipei
Contact:

Post by comaniac »

To Sohel
THX for solving my problem ,too! :lol:

Although after 3 years...
NTHU-CS 11 graduated from SSSH,Taiwan-Taipei
MSN Space
aNobii
All of us have to "Mens et Manus".

toni
New poster
Posts: 7
Joined: Wed Jul 25, 2007 6:03 pm

Post by toni »

Code: Select all

code remove
that is my cpp code , i got the WA
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.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Your code doesn't even pass the samples. Check the spelling please.
Ami ekhono shopno dekhi...
HomePage

toni
New poster
Posts: 7
Joined: Wed Jul 25, 2007 6:03 pm

Post by toni »

Jan wrote:Your code doesn't even pass the samples. Check the spelling please.
god ! that is too horrorable.
Thanks Jan :oops:

paulmcvn
New poster
Posts: 34
Joined: Sat Nov 13, 2004 12:15 pm

Post by paulmcvn »

I think this is so simple but still got WA...

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;
}
I passed all tests in the board
Can anyone help me to find what is wrong here...

kundai
New poster
Posts: 1
Joined: Sun Sep 09, 2007 9:53 am

Same problem - time limit exceeded

Post by kundai »

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);
        }
}

Hikaru78
New poster
Posts: 1
Joined: Tue Sep 18, 2007 12:27 am

Post by Hikaru78 »

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 :)

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");
	}
}

Forgive my lack of comments. // isn't supported by ANSI standard, and the whole /* */ shebang is too much to do quickly.

Arashk_kh68
New poster
Posts: 6
Joined: Sun Sep 09, 2007 3:56 pm

Post by Arashk_kh68 »

Look for your spelling, "Not Jolly" must be "Not jolly", maybe it helps,
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;
}

anyone can help please?!

Rajesh V
New poster
Posts: 2
Joined: Mon Jan 14, 2008 11:25 am

please help - getting WA for jolly jumpers

Post by Rajesh V »

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.

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;
}
Please help me and thanks in advance.

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

Rajesh V,
initialize your array

Code: Select all

int c[n];
c[0] = 1; 
for(int i=1;i<n;++i)c[i]=0;

daichin85
New poster
Posts: 3
Joined: Tue Jul 01, 2008 1:29 pm

Re: 10038 - Jolly Jumpers

Post by daichin85 »

how do i read the input. does it continue endlessly? please just post the reading the input section.

Nishith csedu 1448
New poster
Posts: 4
Joined: Fri May 23, 2008 6:55 am
Location: Dhaka
Contact:

Re: 10038 - Jolly Jumpers

Post by Nishith csedu 1448 »

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!!!!!!!!!!!!
Sopno dhaka mon akash choar.............

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 10038 - Jolly Jumpers

Post by helloneo »

daichin85 wrote:how do i read the input. does it continue endlessly? please just post the reading the input section.
See Rajesh V's code or Hikaru78's code.. :-)

Galileo
New poster
Posts: 3
Joined: Tue Jul 15, 2008 9:30 am

10038 Jolly Jumbers (Run time error)

Post by Galileo »

Hi every one.

Every time I submit my code i get this error:
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.
Although it runs correctly.

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;
    }
}

Post Reply

Return to “Volume 100 (10000-10099)”