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

Echoless
New poster
Posts: 4
Joined: Fri Dec 05, 2014 3:27 am

Re: 10038 - Jolly Jumpers

Post by Echoless » Thu Dec 11, 2014 9:23 pm

I tried all given inputs, and it still gives me a wrong answer. Anyone can tell me what's the problem?

Code: Select all

Tweaked it myself and it finally gave me accepted:)

Lim.YuDe
New poster
Posts: 15
Joined: Sat Dec 13, 2014 1:32 pm

Re: 10038 - Jolly Jumpers

Post by Lim.YuDe » Wed Dec 17, 2014 5:09 pm

I have looked at many posts in this thread and tried all sample input, and also tried the critical input as given on udebug.com, and although I pass all this input I get WA when I submit my code.. does anybody have any idea?

Code: Select all

    Removed after AC
Last edited by Lim.YuDe on Thu Dec 18, 2014 3:18 am, edited 1 time in total.

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

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Wed Dec 17, 2014 10:06 pm

Change line 21 from:
memset(numbers, 0, 3000);
to:
memset(numbers, 0, sizeof(numbers));

http://www.cplusplus.com/reference/cstring/memset/

The third argument is the number of bytes, an int is 4 bytes.
Check input and AC output for thousands of problems on uDebug!

Lim.YuDe
New poster
Posts: 15
Joined: Sat Dec 13, 2014 1:32 pm

Re: 10038 - Jolly Jumpers

Post by Lim.YuDe » Thu Dec 18, 2014 3:16 am

Thank you Brianfry713! Just got AC!

qz63
New poster
Posts: 2
Joined: Mon Dec 29, 2014 11:07 am

Re: 10038 - Jolly Jumpers_Java Runtime Error

Post by qz63 » Mon Dec 29, 2014 11:15 am

Hi guys. I have a problem in this question. I keep getting a Runtime Error. Would you guys have a look at my code and give some advice? Thanks. Here is my code.

Code: Select all

AC removed
Last edited by qz63 on Tue Dec 30, 2014 9:56 am, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10038 - Jolly Jumpers

Post by lighted » Tue Dec 30, 2014 9:46 am

Don't think that input ends with 0 or negative number. You should check if input has next int.

Code: Select all

if (input.hasNextInt()) 
    n = input.nextInt();
else 
    break;
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

qz63
New poster
Posts: 2
Joined: Mon Dec 29, 2014 11:07 am

Re: 10038 - Jolly Jumpers

Post by qz63 » Tue Dec 30, 2014 9:56 am

Thanks, lighted. I just figured it out like what you said. Thanks anyway.

franmzy
New poster
Posts: 1
Joined: Sun Apr 19, 2015 7:15 pm

I can't make it work in UVa's judge

Post by franmzy » Sun Apr 19, 2015 7:40 pm

Hi everyone!

I've been solving problems acording the programming-challenges site judge and when I tried to solve the Jolly Jumpers problem with the UVa judge I got WA.
I've tried every set of tests you suggestes and I get the correct answers.

I'd be pleased if you could help me to find my error. Here's my C ANSI code, I've used binary operations to solve it.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char const *argv[])
{
	long int n, i, num, ant;
	unsigned long int target, counter;
	char c;

	while(scanf("%ld", &n) != EOF){
		if (n<=0)
		{
			while((c = getchar()) != '\n' && (c = getchar()) != EOF);
			printf("Not jolly\n");
			continue;
		}
		
		target = pow(2,n)-1; // Example if n = 4 -> target = 1111 -> counter = 0001 
		counter = 1;             // positions 3, 2, 1 need to be filled to get a Jolly number
		
		scanf(" %ld", &ant);
		for (i = 1; i < n; ++i)
		{	
			scanf(" %ld", &num);
			counter = (counter | (unsigned long int)pow(2,abs(ant - num)));
			ant = num;
		}
		while((c = getchar()) != '\n' && (c = getchar()) != EOF);
		if (target == counter)
		{
			printf("Jolly\n");
		}
		else
		{
			printf("Not jolly\n");
		}
	}
	return 0;
}

Zedi
New poster
Posts: 2
Joined: Mon Aug 31, 2015 10:40 am

Re: 10038 - Jolly Jumpers

Post by Zedi » Mon Aug 31, 2015 10:47 am

I got Runtime Error on UVA, WA on Programming Challenges.

Any recommendation for my code or test case will be appreciated!

TY

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){

	int nums[3000];
	int num_checks[3000];
	int num;
	char ch;
	char char_num[4];
	char line[10000];

	while (1){ // 케이스 별

		int i = 0;
		//int exit = 0;
		int jolly = 1;
		
		while ( !((ch = getchar()) == ' ' )){ // 처음 숫자를 입력받는다.
			char_num[i++] = ch;
			if (ch == '\n') break;
		}

		if (char_num[0] == '\n') break;

		num = atoi(char_num);

		if (ch == '\n') {
			if (num == 1) puts("Jolly");
			else puts("Not jolly");
			continue;
		}

		for (i = 0; i < num; i++){
			scanf("%d", &nums[i]);
			//getchar(); // 스페이스바
			//printf("%d ", nums[i]);

			if (i != num - 1) // 인덱스가 0 ~ num - 2 까지 되도록
				num_checks[i] = i + 1; // 들어간 숫자는 1 ~ num - 1
		}		

		int index;

		for (i = 1; i < num; i++){

			index = abs(nums[i] - nums[i - 1]) - 1;

			if (index >= num - 1 || index == -1 || num_checks[index] == 0){
				jolly = 0;
				break;
			}
			num_checks[index] = 0;
		}

		gets(line);

		if (jolly) puts("Jolly");
		else puts("Not jolly");
	}

	return 0;
}

saadmanheavy
New poster
Posts: 2
Joined: Fri Dec 11, 2015 9:43 pm

Re: 10038 - Jolly Jumpers

Post by saadmanheavy » Fri Dec 11, 2015 9:46 pm

What is wrong with this code:

Code: Select all

#include <stdio.h>
#include <math.h>

int main()
{
    int n;
    int ar[3001];
    while(scanf("%d", &n)!=EOF)
    {
        int ar1[n-1],i,flag=0;
        for(i=0; i<n; i++)
        {
            scanf("%d", &ar[i]);
        }
        for (i=0; i<n; i++)
        {
            ar[i]=abs(ar[i]);
        }
        int j=0,k=0;
        for(i=0; i<n-1; i++)
        {
            if(ar[j]>ar[j+1])
            {
                ar1[k]=ar[j]-ar[j+1];
                j++;
                k++;
            }
            else
            {
                ar1[k]=ar[j+1]-ar[j];
                j++;
                k++;
            }
        }
        for(i=0;i<n-1;i++){
            printf("%d ", ar1[i]);
        }
        i=0;
        while(i<n-2){
            if(ar1[0]!=n && ((ar1[i]-ar1[i+1]==0)||(ar1[i]-ar1[i+1]==1))&& ar1[n-2]==1){
                flag=1;
            }
            i++;
        }
        if(flag==1)printf("Jolly\n");
        else printf("Not Jolly\n");
    }
    return 0;
}

souravvv
New poster
Posts: 2
Joined: Wed Nov 25, 2015 5:49 am

10038 - Jolly Jumpers

Post by souravvv » Fri Apr 29, 2016 5:44 pm

I am getting RTE. WHY :(

Code: Select all

#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

typedef long long int lli;


int main(){
   lli n,temp,index;
   vector <lli> data;
   vector <bool> check;
   bool result;
  
   while( 1 ){
      cin >> n;
      if( n == 0 )
         break;
      check.clear();
      data.clear();
      result = true;
      for( lli i = 0; i < n; i++ ){
         cin >> temp;
         data.push_back( temp );
      }
      
      for( lli i = 0; i < n - 1; i++ ){
         check.push_back( false );
      }
      
      for( lli i = 1; i < n; i++ ){
         index = abs( data[i] - data[i - 1] ) - 1;
         if( index <= (n - 2 ) )
            check[ index ] = true;
      }
      for( lli i = 0; i < check.size(); i++ ){
         if( check[i] == false )
            result = false;
      }
 
      if( result )
         cout << "Jolly" << endl;
      else
         cout << "Not jolly" << endl;
      
   }
}

Post Reply

Return to “Volume 100 (10000-10099)”