10038 - Jolly Jumpers
Moderator: Board moderators
-
- New poster
- Posts: 6
- Joined: Fri Aug 15, 2003 9:12 am
10038 Jolly Jumper Runtime Error help
Hey The online judge gives this message....
Your program has died with signal 6 (SIGABRT). Meaning:
Abort signal from abort()
Before crash, it ran during 0.000 seconds.
I don't know what does that mean
here is my code
[cpp]#include <iostream>
#include <cstdlib>
using namespace std;
int n;
void fillP(int *j);
int isempty(int *p);
int main() {
int inp1, inp2,*j;
int counter;
while (1) {
cin >> n;
if (n==0) break;
counter = n - 1;
j = new int[n-1];
fillP(j);
cin >> inp1;
for (int i=1; i < n; i++) {
cin >> inp2;
counter = abs(inp2 - inp1);
if ((counter >= n)||(counter <= 0)) break;
j[counter - 1] = -1;
inp1 = inp2;
}
if (!isempty(j)) cout << "Not Jolly\n";
else cout << "Jolly\n";
delete [] j;
}
return 0;
}
void fillP(int *j) {
for (int i =0; i < n-1; i++)
j = i+1;
}
int isempty(int *p) {
for (int i = 0; i < n; i++) {
if (p >= 0) return 0;
}
return 1;
}[/cpp]
Your program has died with signal 6 (SIGABRT). Meaning:
Abort signal from abort()
Before crash, it ran during 0.000 seconds.
I don't know what does that mean
here is my code
[cpp]#include <iostream>
#include <cstdlib>
using namespace std;
int n;
void fillP(int *j);
int isempty(int *p);
int main() {
int inp1, inp2,*j;
int counter;
while (1) {
cin >> n;
if (n==0) break;
counter = n - 1;
j = new int[n-1];
fillP(j);
cin >> inp1;
for (int i=1; i < n; i++) {
cin >> inp2;
counter = abs(inp2 - inp1);
if ((counter >= n)||(counter <= 0)) break;
j[counter - 1] = -1;
inp1 = inp2;
}
if (!isempty(j)) cout << "Not Jolly\n";
else cout << "Jolly\n";
delete [] j;
}
return 0;
}
void fillP(int *j) {
for (int i =0; i < n-1; i++)
j = i+1;
}
int isempty(int *p) {
for (int i = 0; i < n; i++) {
if (p >= 0) return 0;
}
return 1;
}[/cpp]
The WA way.
Greetings!.
It took me about 3 WAs in one of my progrmas to realize it's best to COPY and PASTE the examples
It took me about 3 WAs in one of my progrmas to realize it's best to COPY and PASTE the examples

_.
Great!.
Thanks for the hint!Kentaro wrote:All the numbers from 1 to 5 are seen at least once in the above list so the sequence is a jolly jumper. They don't have to be seen in any particular order.
EDIT: Read the problem statement carefully.

Keep posting!.
_.
Read the input specification:Onko wrote:Hmm I still don't understand:
For sequence 6 1 4 3 7 5 10, the differences are:
5 3 1 4 2 5 -> but 6 is missing here, so shouldn't it be "Not jolly", since n = 7?
Thanks.
wrt the input specification the first number on the line is the value n, followed by the n values representing the sequence.Each line of input contains an integer n <= 3000 followed by n integers representing the sequence.
Ciao!!!
Claudio
-
- New poster
- Posts: 8
- Joined: Thu Jun 17, 2004 5:50 am
10038 - WA Need Help
I keep getting WA with the following (or variations of the same):
[c++]
#include <iostream>
using namespace std;
const int MAX = 3001;
struct RangeToTest
{
int range;
int array[MAX];
bool checkJolly()
{
int temp[MAX];
for(int i=0; i<range-1; ++i)
{
if(array < array[i+1])
{
temp = array[i+1] - array;
}
else
temp = array - array[i+1];
}
for(int i=0; i<range-1; ++i)
{
int check = checkForDuplicate(temp, temp, range-1);
if(check > 1)
return false;
if(temp >= 1 && temp <= range-1)
continue;
else
return false;
}
return true;
}
int checkForDuplicate(int *x, int n, int size)
{
int count = 0;
for(int i=0; i<size; ++i)
{
if(x == n)
count++;
}
return count;
}
};
int main()
{
int n, i;
while(cin >> n)
{
if(n >= 3000 || n <= 0)
exit(1);
RangeToTest s;
s.range = n;
for(int x=0; x<n; ++x)
{
cin >> i;
s.array[x] = i;
}
if(s.checkJolly())
cout << "Jolly\n";
else
cout << "Not Jolly\n";
}
return 0;
}
Anyone see the problem?
Thanks,
Matt
[c++]
#include <iostream>
using namespace std;
const int MAX = 3001;
struct RangeToTest
{
int range;
int array[MAX];
bool checkJolly()
{
int temp[MAX];
for(int i=0; i<range-1; ++i)
{
if(array < array[i+1])
{
temp = array[i+1] - array;
}
else
temp = array - array[i+1];
}
for(int i=0; i<range-1; ++i)
{
int check = checkForDuplicate(temp, temp, range-1);
if(check > 1)
return false;
if(temp >= 1 && temp <= range-1)
continue;
else
return false;
}
return true;
}
int checkForDuplicate(int *x, int n, int size)
{
int count = 0;
for(int i=0; i<size; ++i)
{
if(x == n)
count++;
}
return count;
}
};
int main()
{
int n, i;
while(cin >> n)
{
if(n >= 3000 || n <= 0)
exit(1);
RangeToTest s;
s.range = n;
for(int x=0; x<n; ++x)
{
cin >> i;
s.array[x] = i;
}
if(s.checkJolly())
cout << "Jolly\n";
else
cout << "Not Jolly\n";
}
return 0;
}
Anyone see the problem?
Thanks,
Matt
10038 - Java Implementation. WA
Hi, Ive been going over this problem and can't get it to work.
Can anyone help with where the codes wrong.
- 1st post so excuse me if I bugger up the pasted code.
[java]
import java.util.*;
import java.io.*;
class Main {
static final int BUFFER = 24000;
public static void main(String [] args){
Main myProg = new Main();
myProg.begin();
}//main.
void begin(){
String line = null;
//Use array of booleans to indicate all values present (Index is Difference
// value).
boolean [] list;
boolean jolly = true, first = true;
StringTokenizer str;
int index = 0, num1 = 0, num2=0;
while ((line = readln(BUFFER)) != null) {
if (!first) System.out.println();
str = new StringTokenizer(line);
index = Integer.parseInt(str.nextToken());
if (index == 1){ //Single int therefore - Jolly.
System.out.print("Jolly");
continue;
} else if (index <= 0) {
System.out.print("Not jolly");
continue;
}
//Create bool array to hold indicators.
list = new boolean [index];
list[0] = true; //Set index 0 to true.
num1 = Integer.parseInt(str.nextToken()); //Get 1st number
int diff = 0;
while (str.hasMoreTokens()){ //Loop while numbers are present
num2 = Integer.parseInt(str.nextToken());
diff = Math.abs(num1 - num2);
if (diff >= index) {
jolly = false;
break; //Difference not in range 1 - (n-1) so Not Jolly
}//if
//If array index position set true already, must be Not Jolly
// as duplicate difference values.
if (list[diff]){
jolly = false;
break;
} else {
list[diff] = true;
}//Else
num1 = num2;
diff =0;
}//While
if (jolly) { //If Jolly so far check Bool array is all true.
for(int i=0; i<index; i++){
if (list == false)
jolly = false;
}//For - Array content
}//if
if (jolly){
System.out.print("Jolly");
}
else
System.out.print("Not jolly");
num1 = 0;
num2 = 0;
index = 0;
jolly = true;
first = false;
list = null;
}//While
}//Begin
static String readln (int LEN)
{
byte lin[] = new byte [LEN];
int lg = 0, car = -1;
String line = "";
try {
while (lg < LEN)
{
car = System.in.read();
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));
}//ReadLn
}//Main.
[/java][/java][/b]
Can anyone help with where the codes wrong.
- 1st post so excuse me if I bugger up the pasted code.
[java]
import java.util.*;
import java.io.*;
class Main {
static final int BUFFER = 24000;
public static void main(String [] args){
Main myProg = new Main();
myProg.begin();
}//main.
void begin(){
String line = null;
//Use array of booleans to indicate all values present (Index is Difference
// value).
boolean [] list;
boolean jolly = true, first = true;
StringTokenizer str;
int index = 0, num1 = 0, num2=0;
while ((line = readln(BUFFER)) != null) {
if (!first) System.out.println();
str = new StringTokenizer(line);
index = Integer.parseInt(str.nextToken());
if (index == 1){ //Single int therefore - Jolly.
System.out.print("Jolly");
continue;
} else if (index <= 0) {
System.out.print("Not jolly");
continue;
}
//Create bool array to hold indicators.
list = new boolean [index];
list[0] = true; //Set index 0 to true.
num1 = Integer.parseInt(str.nextToken()); //Get 1st number
int diff = 0;
while (str.hasMoreTokens()){ //Loop while numbers are present
num2 = Integer.parseInt(str.nextToken());
diff = Math.abs(num1 - num2);
if (diff >= index) {
jolly = false;
break; //Difference not in range 1 - (n-1) so Not Jolly
}//if
//If array index position set true already, must be Not Jolly
// as duplicate difference values.
if (list[diff]){
jolly = false;
break;
} else {
list[diff] = true;
}//Else
num1 = num2;
diff =0;
}//While
if (jolly) { //If Jolly so far check Bool array is all true.
for(int i=0; i<index; i++){
if (list == false)
jolly = false;
}//For - Array content
}//if
if (jolly){
System.out.print("Jolly");
}
else
System.out.print("Not jolly");
num1 = 0;
num2 = 0;
index = 0;
jolly = true;
first = false;
list = null;
}//While
}//Begin
static String readln (int LEN)
{
byte lin[] = new byte [LEN];
int lg = 0, car = -1;
String line = "";
try {
while (lg < LEN)
{
car = System.in.read();
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));
}//ReadLn
}//Main.
[/java][/java][/b]
#$%@# 10038 WA --Heeeeelllpppp
Hi, Ive already posted this at the appropriate place but Im not getting any help there.
I originally tried reading an enitire line, but changed tack to read individual set of numbers from input file (Runs much quicker).
However I still keep getting the dreaded WA.
Test Data: (From Another Post).
[java]
import java.util.*;
import java.io.*;
class Main {
static final int BUFFER = 100;
public static void main(String [] args){
Main myProg = new Main();
myProg.begin();
}//main.
void begin(){
String line = null;
boolean [] list;
boolean jolly = true, first = true;
long index = 0, number =0, num1 = 0, num2=0, count =0;
while ((line = readln(BUFFER)) != null) {
if (line.equals("")){
continue;
}
count++;
number = Long.parseLong(line);
if (count == 1) {//if count is 1 then number is the index number.
index = number;
if (index == 1){ //Single int therefore - Jolly.
line = readln(BUFFER);
count = 0;
System.out.println("Jolly");
continue;
} else if (index <= 0) {
count = 0;
System.out.println("Not jolly");
for(int i =0; i<(Math.abs(index)); i++){
line = readln(BUFFER);
}
continue;
}
number = 0; //Got the index number get next number
}//If Index Check
list = new boolean [(int)index]; //Create bool array to hold indicators.
list[0] = true; //Set index 0 to true.
num1 = Long.parseLong(readln(BUFFER));
int diff = 0;
for(int loop =0; loop<index-1; loop++){
String temp = readln(BUFFER);
num2 = Long.parseLong(temp);
diff = (int)Math.abs(num1 - num2);
if (diff >= index) {
jolly = false;
for(int nums = loop; nums<index-1; nums++){
line = readln(BUFFER);
}
break; //Difference not in range 1 - (n-1) so Not Jolly
}//if
if (list[diff]){
jolly = false;
for(int j=loop; j<index-1; j++){
line = readln(BUFFER);
}
break;
} else {
list[diff] = true;
}//Else
num1 = num2;
diff =0;
}//For
if (jolly) { //If Jolly so far check Bool array is all true.
for(int i=0; i<index; i++){
if (list == false)
jolly = false;
}//For - Array content
}//if
if (jolly){
System.out.println("Jolly");
}
else
System.out.println("Not jolly");
num1 = 0;
num2 = 0;
number =0;
index = 0;
count = 0;
jolly = true;
first = false;
list = null;
}//While
}//Begin
static String readln (int LEN)
{
byte lin[] = new byte [LEN];
int lg = 0, car = -1;
String line = "";
try {
while (lg < LEN)
{
car = System.in.read();
if ((car < 0) || (car == '\n') || (car == ' ')) break;
lin [lg++] += car;
}
} catch (IOException e){
return (null);
}
if ((car < 0) && (lg == 0)) return (null);
return (new String (lin, 0, lg));
}//ReadLn
}//Main.
[/java]
Any Help would be greatly appreciated !
Thanks
[/list]
I originally tried reading an enitire line, but changed tack to read individual set of numbers from input file (Runs much quicker).
However I still keep getting the dreaded WA.
Test Data: (From Another Post).
- 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
1 4645445455
0
-5 2 34 5 7 88
- Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Jolly
Jolly
Not jolly
Not jolly
Jolly
Jolly
Jolly
Not jolly
Not jolly
[java]
import java.util.*;
import java.io.*;
class Main {
static final int BUFFER = 100;
public static void main(String [] args){
Main myProg = new Main();
myProg.begin();
}//main.
void begin(){
String line = null;
boolean [] list;
boolean jolly = true, first = true;
long index = 0, number =0, num1 = 0, num2=0, count =0;
while ((line = readln(BUFFER)) != null) {
if (line.equals("")){
continue;
}
count++;
number = Long.parseLong(line);
if (count == 1) {//if count is 1 then number is the index number.
index = number;
if (index == 1){ //Single int therefore - Jolly.
line = readln(BUFFER);
count = 0;
System.out.println("Jolly");
continue;
} else if (index <= 0) {
count = 0;
System.out.println("Not jolly");
for(int i =0; i<(Math.abs(index)); i++){
line = readln(BUFFER);
}
continue;
}
number = 0; //Got the index number get next number
}//If Index Check
list = new boolean [(int)index]; //Create bool array to hold indicators.
list[0] = true; //Set index 0 to true.
num1 = Long.parseLong(readln(BUFFER));
int diff = 0;
for(int loop =0; loop<index-1; loop++){
String temp = readln(BUFFER);
num2 = Long.parseLong(temp);
diff = (int)Math.abs(num1 - num2);
if (diff >= index) {
jolly = false;
for(int nums = loop; nums<index-1; nums++){
line = readln(BUFFER);
}
break; //Difference not in range 1 - (n-1) so Not Jolly
}//if
if (list[diff]){
jolly = false;
for(int j=loop; j<index-1; j++){
line = readln(BUFFER);
}
break;
} else {
list[diff] = true;
}//Else
num1 = num2;
diff =0;
}//For
if (jolly) { //If Jolly so far check Bool array is all true.
for(int i=0; i<index; i++){
if (list == false)
jolly = false;
}//For - Array content
}//if
if (jolly){
System.out.println("Jolly");
}
else
System.out.println("Not jolly");
num1 = 0;
num2 = 0;
number =0;
index = 0;
count = 0;
jolly = true;
first = false;
list = null;
}//While
}//Begin
static String readln (int LEN)
{
byte lin[] = new byte [LEN];
int lg = 0, car = -1;
String line = "";
try {
while (lg < LEN)
{
car = System.in.read();
if ((car < 0) || (car == '\n') || (car == ' ')) break;
lin [lg++] += car;
}
} catch (IOException e){
return (null);
}
if ((car < 0) && (lg == 0)) return (null);
return (new String (lin, 0, lg));
}//ReadLn
}//Main.
[/java]
Any Help would be greatly appreciated !
Thanks

-
- New poster
- Posts: 2
- Joined: Sun Aug 01, 2004 7:19 am
- Contact:
10038 WA
I have code that gets accepted. But one little modification gives me WA, not sure why.
Here's the code that gets accepted:
[cpp]
/* @JUDGE_ID: 48307RK 10038 C++ "Jolly Jumpers" */
/* @BEGIN_OF_SOURCE_CODE */
#include <cstdio>
#include <string>
#include <cmath>
const int MAX_SEQ_SIZE = 4000;
long seq[MAX_SEQ_SIZE];
int main(int argc, char** argv)
{
long n;
long current;
long prev;
long diff;
int is_jolly;
while ( (scanf("%ld", &n)) != EOF ) {
//printf("Seq of size %d\n", n);
prev=0;
is_jolly=1;
diff=0;
int i;
memset(seq, 0, MAX_SEQ_SIZE); // initialize the array for new line of input
for(i=0; i < n; i++) {
scanf("%ld", ¤t);
if ( i > 0 ) { // if not the first number, don't need to find diff for
// first number
diff = labs(current - prev);
//printf("i,prev,current,diff=%ld,%ld,%ld,%ld\n", i, prev, current, diff);
if ( diff < n && diff > 0) {
seq[diff]++;
} // if ( diff >=
} // if ( i > 0 )
prev = current;
} // for
// Check if all the numbers between 1 and n-1 are set
for ( int i=1; i < n; i++) {
if (!seq) {
is_jolly=0;
}
}
if (is_jolly) {
printf("Jolly\n");
} else {
printf("Not jolly\n");
}
} // while
}// main
/* @END_OF_SOURCE_CODE */
[/cpp]
if I change the if stmt
if (!seq)
{
is_jolly = 0;
}
to
if(seq != 1) {
is_jolly = 0
}
I get WA. If all numbers between 1 and n-1 are found in the differences of successive numbers, shouldn't all the array indices be set to 1? What test case would give me a seq != 1 and it will still be Jolly? Can someone find such a testcase?
Here's the code that gets accepted:
[cpp]
/* @JUDGE_ID: 48307RK 10038 C++ "Jolly Jumpers" */
/* @BEGIN_OF_SOURCE_CODE */
#include <cstdio>
#include <string>
#include <cmath>
const int MAX_SEQ_SIZE = 4000;
long seq[MAX_SEQ_SIZE];
int main(int argc, char** argv)
{
long n;
long current;
long prev;
long diff;
int is_jolly;
while ( (scanf("%ld", &n)) != EOF ) {
//printf("Seq of size %d\n", n);
prev=0;
is_jolly=1;
diff=0;
int i;
memset(seq, 0, MAX_SEQ_SIZE); // initialize the array for new line of input
for(i=0; i < n; i++) {
scanf("%ld", ¤t);
if ( i > 0 ) { // if not the first number, don't need to find diff for
// first number
diff = labs(current - prev);
//printf("i,prev,current,diff=%ld,%ld,%ld,%ld\n", i, prev, current, diff);
if ( diff < n && diff > 0) {
seq[diff]++;
} // if ( diff >=
} // if ( i > 0 )
prev = current;
} // for
// Check if all the numbers between 1 and n-1 are set
for ( int i=1; i < n; i++) {
if (!seq) {
is_jolly=0;
}
}
if (is_jolly) {
printf("Jolly\n");
} else {
printf("Not jolly\n");
}
} // while
}// main
/* @END_OF_SOURCE_CODE */
[/cpp]
if I change the if stmt
if (!seq)
{
is_jolly = 0;
}
to
if(seq != 1) {
is_jolly = 0
}
I get WA. If all numbers between 1 and n-1 are found in the differences of successive numbers, shouldn't all the array indices be set to 1? What test case would give me a seq != 1 and it will still be Jolly? Can someone find such a testcase?
10038 Why Wa
@Thish is my code
i can't understand why it gives wa pleze help me
#include<stdio.h>
#include<math.h>
int n;
long inte[3000];
long diff[3000];
long i;
int mutex;
void main()
{
while(1==scanf("%d",&n))
{
if(n>3000)
break;
if(n==0)
{
printf("Not jolly");
}
else
{
for(i=0;i<n;i++)
scanf("%ld",&inte);
for(i=0;i<n-1;i++)
diff=abs(inte-inte[i+1]);
for(i=0;i<n-1;i++)
{
if((abs(diff-diff[i+1])!=1))
{
mutex=1;
break;
}
else
mutex=0;
}
if(mutex==0)
printf("Jolly\n");
else
printf("Not jolly\n");
mutex=0;
}
}
}
i can't understand why it gives wa pleze help me
#include<stdio.h>
#include<math.h>
int n;
long inte[3000];
long diff[3000];
long i;
int mutex;
void main()
{
while(1==scanf("%d",&n))
{
if(n>3000)
break;
if(n==0)
{
printf("Not jolly");
}
else
{
for(i=0;i<n;i++)
scanf("%ld",&inte);
for(i=0;i<n-1;i++)
diff=abs(inte-inte[i+1]);
for(i=0;i<n-1;i++)
{
if((abs(diff-diff[i+1])!=1))
{
mutex=1;
break;
}
else
mutex=0;
}
if(mutex==0)
printf("Jolly\n");
else
printf("Not jolly\n");
mutex=0;
}
}
}
Perhaps the difference between two consecutive numbers does not ascend (or decend) sequentaly. Consieder the sequence 1 2 5 3. Your program tells you that it's not jolly, but actualy it is because the difference between the elements are 1, 3 and 2 which are all the values from 1 to 3. I hope this helps.
10038
I don't know why i get WA with this code....I was reading others posts and i couldn't find nothing that my code didn't cover.
Someone can help me?
Someone can help me?
Code: Select all
#include<iostream>
#include<stdio.h>
#include<string>
using std::cout;
using std::cin;
using std::endl;
int main()
{
char c;
while ((c = getchar()) != '\n')
{
cin.putback(c);
int n;
cin >> n;
long int sequence[3003];
for ( int i = 1; i <= n; i++ )
cin >> sequence[i];
long int diferenca[3002];
for ( int i = 1; i <= n-1; i++ )
diferenca[i] = 0;
for ( int i = 2; i <= n; i++ )
{
int index = abs(sequence[i-1] - sequence[i]);
if ( index < 3003 )
diferenca[index] = 1;
}
int cont = 0;
for ( int i = 1; i <= n-1; i++ )
if ( diferenca[i] == 1 )
cont++;
if ( cont == n-1 )
cout << "Jolly"<< endl;
else
cout << "Not jolly" << endl;
}
}