10038 - Jolly Jumpers
Moderator: Board moderators
Thanks Daveon,, but
Yes, my code says 1 is jolly but still got wrong answer... I don't know what to do... falling in panic...
Ah, if you can, it is very kind of you to give some test cases...
Ah, if you can, it is very kind of you to give some test cases...
-
- New poster
- Posts: 3
- Joined: Tue Jan 09, 2007 1:41 pm
10038always WA!!
well, this is killing me...
plz help me with this
i have tried many times but always get WA 
plz help me with this
Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int n, i, ans, found=1;
long num[3000]={0};
char selisih[3000];
scanf("%d", &n);
memset (selisih, 0, sizeof (char)*3000);
for(i=1;i<=n;i++)
{
scanf("%ld", &num[i]);
if(i==n)
break;
}
if(n==1)
found=1;
for(i=2;i<=n;i++)
{
ans=abs(num[i]-num[i-1]);
if ((ans < n) && (ans != 0))
{
if (selisih[ans] == 0)
selisih[ans] = 1;
else
found = 0;
}
else found = 0;
}
if(found==0)
printf("Not jolly\n");
else
printf("Jolly\n");
return 0;
}

Code: Select all
-
- New poster
- Posts: 3
- Joined: Tue Jan 09, 2007 1:41 pm
it doesn't work..
sorry still WA
10038 why Time Limit Exceeded
Code is here tell me why it exceeded time limit??
#include<stdio.h>
#include<math.h>
**********Code Removed**************
#include<stdio.h>
#include<math.h>
**********Code Removed**************
Last edited by ranacse05 on Tue Apr 10, 2007 1:55 pm, edited 1 time in total.
Code: Select all
while(scanf("%d",&num))
Code: Select all
while(scanf("%d",&num) == 1)
10038 Jolly Jumpers - WA - Need help please
Sorry about the new topic.
Someone can help why my code gets WA?

Someone can help why my code gets WA?
Code: Select all
#include <iostream>
using namespace std;
int main(){
int n, num1, num2, trash;
bool bool1, bool2;
while(cin >> n){
bool1=false;
bool2=true;
if (n>1){
for(int i =0; i<(n-1); i++){
if (i==0){
cin >> num1 >> num2;
}
else{
num1=num2;
cin >> num2;
}
if(num1>num2){
if ((num1-num2)==(n-1)){
bool1=true;
}
else{
if((num1-num2)>(n-1))
bool2=false;
}
}
else{
if ((num2-num1)==(n-1)){
bool1=true;
}
else{
if((num2-num1)>(n-1)||((num2-num1)==0))
bool2=false;
}
}
}
if(bool2==false)
cout << "Not Jolly" << endl;
else{
if(bool1==true)
cout << "Jolly" << endl;
else
cout << "Not Jolly" << endl;
}
}
else{
if (n<=0)
return 0;
else{
cin >> trash;
cout << "Jolly" << endl;
}
}
}//end while
return 0;
}

10038 - Wrong Answer
I was trying to solve the Jolly Jumpers problem, but i got a wrong answer 
here is my java code:
I' ve tried to this input:
and the result is...
It's ok, isn't?
does anybody help me?
thanks

here is my java code:
Code: Select all
import java.io.IOException;
import java.util.StringTokenizer;
class Main {
static String ReadLn(int maxLg) {
byte lin[] = new byte[maxLg];
int lg = 0, car = -1;
try {
while (lg < maxLg) {
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));
}
public static void main(String args[]) {
Main myWork = new Main();
myWork.begin();
}
void begin() {
while (true) {
String input = ReadLn(255);
StringTokenizer token = new StringTokenizer(input);
int n = Integer.parseInt(token.nextToken());
int[] v = new int[n];
for (int i = 0; i < n; i++)
v[i] = Integer.parseInt(token.nextToken());
resolve(n,v);
}
}
void resolve(int n, int[] v){
boolean condi = false;
boolean[] z = new boolean[n];
for (int i = 0; i < n; i++)
z[i] = false;
for (int i = 0; i < n-1; i++) {
int valor = Math.abs(v[i] - v[i + 1]);
if (valor >= n)
condi = false;
else if (valor -1 >= 0)
z[valor-1] = true;
}
if (condi)
System.out.println("Not jolly");
else {
boolean troca = true;
for(int i = 0; i < n-1; i++) {
if (z[i] == false){
troca = false;
break;
}
}
if (troca)
System.out.println("Jolly");
else
System.out.println("Not jolly");
}
}
}
Code: Select all
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
5 3 4 2 3 5
9 5 6 4 1 -3 2 8 15 7
9 10 5 1 4 6 12 19 27 36
9 10 5 1 4 6 12 19 27 26
Code: Select all
Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Jolly
Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Not jolly
does anybody help me?
thanks
hmmm some diff....check my output form my ac code...
may it help u....
GOOD LUCK
Rocky
Code: Select all
Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Jolly
Jolly
Not jolly
Not jolly
Not Jolly
Jolly
Not jolly
Jolly
Not jolly
Jolly
GOOD LUCK
Rocky
My AC program has a slightly different output than the one above.
My AC program outputs:
As for which one is correct, it all comes down to the following input:
Since there is only one integer, shouldn't the correct output be "Jolly"?
My AC program outputs:
Code: Select all
Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Jolly
Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Not jolly
Jolly
Code: Select all
1 2
Rocky, thanks for your help!
chunyi81, the result of what you've said is
as you see, my result matches yours, but what is wrong? Do you have any test cases for this problem?
chunyi81, the result of what you've said is
Code: Select all
1 2
Jolly