Page 26 of 30
10038 - Jolly Jumpers WA
Posted: Sun Mar 30, 2014 3:02 pm
by godsont
Hi, I'm new to this site. I have tried solving the problem called Jolly Jumpers but got a Wrong Answer. I have tried a couple of times. Please help me find the error in the code below. I have tested with the input example in the problem and got the output right.
Code: Select all
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(){
int n, input[3000], difference[3000], status=0, temp;
while(cin>>n){
if(n>1 || n<3000){
for(int i=0; i<n; i++){
cin>>input[i];
}
for(int i=0; i<n-1; i++){
difference[i] = abs(input[i] - input[i+1]);
}
// sort
for(int i = 0; i<n-1; i++){
for(int j = 0; j<i; j++){
if(difference[i] < difference[j]){
temp = difference[j];
difference[j] = difference[i];
difference[i] = temp;
}
}
}
for(int i = 0; i<n-1; i++){
if(difference[i] != i+1){
status = 0;
}
else{
status = 1;
}
}
if(status == 0){
cout<<"Not jolly"<<endl;
}
else {
cout<<"Jolly"<<endl;
}
}
}
return 0;
}
Re: 10038 - Jolly Jumpers WA
Posted: Mon Mar 31, 2014 11:05 pm
by brianfry713
4 1 2 3 6 is Not jolly
10038 Jolly Jumpers Code works but return WA
Posted: Tue Apr 01, 2014 7:41 pm
by mhsn06
Code: Select all
#include <stdio.h>
int main()
{
int n;
while(scanf("%d", &n) == 1)
{
int y=0, s=0, isFirst=1, i;
for(i=0; i<n; i++)
{
int temp=y;
scanf("%d", &y);
if(isFirst)
{
isFirst = 0;
continue;
}
s += abs(temp-y);
}
if(s==((i*(i-1))/2))
{
printf("Jolly\n");
}
else
{
printf("Not jolly\n");
}
}
return 0;
}
Re: 10038 Jolly Jumpers Code works but return WA
Posted: Tue Apr 01, 2014 9:32 pm
by brianfry713
4 1 7 7 7 is not jolly
Re: 10038 - Jolly Jumpers WA
Posted: Wed Apr 02, 2014 5:26 pm
by godsont
hi brianfry713, I have made a change in the program and now the sequence you provided is providing correct output. Please have a look at what else is the error in the program.
Here's the edited code:
Code: Select all
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(){
int n, input[3000], difference[3000], status=0, temp;
while(cin>>n){
if(n>1 || n<3000){
for(int i=0; i<n; i++){
cin>>input[i];
}
for(int i=0; i<n-1; i++){
difference[i] = abs(input[i] - input[i+1]);
}
// sort
for(int i = 0; i<n-1; i++){
for(int j = 0; j<i; j++){
if(difference[i] < difference[j]){
temp = difference[j];
difference[j] = difference[i];
difference[i] = temp;
}
}
}
for(int i = 0; i<n-1; i++){
if(difference[i] != i+1){
status = 0;
break;
}
else{
status = 1;
}
}
if(status == 0){
cout<<"Not jolly"<<endl;
}
else {
cout<<"Jolly"<<endl;
}
}
}
return 0;
}
Re: 10038 - Jolly Jumpers WA
Posted: Wed Apr 02, 2014 9:52 pm
by brianfry713
The definition implies that any sequence of a single integer is a jolly jumper.
Input:
Correct output:
10038 why getting WA
Posted: Sat Apr 12, 2014 12:52 pm
by b1gm4f14
#include<stdio.h>
#include<math.h>
int main()
{
int a[3000],b[3000],i,j,t,s;
scanf("%d",&t);
for(i=1;i<=t;i++)
scanf("%d",&a);
for(i=1;i<t;i++)
{
b=abs(a-a[i+1]);
}
if(b[1]>b[2])
{
for(j=1;j<t-1;j++)
{
if(b[j]-1!=b[j+1])
{
printf("Not jolly\n");
break;
}
if(j==(t-2))
printf("Jolly\n");
}
}
if(b[1]<b[2])
{
for(j=1;j<t-1;j++)
{
if(b[j]+1!=b[j+1])
{
printf("Not jolly\n");
break;
}
if(j==(t-2))
printf("Jolly\n");
}
}
return 0;
}
10038 why getting WA
Posted: Sun Apr 13, 2014 7:21 pm
by b1gm4f14
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
int a[3010],b[3010],c[3001],i,j,t,s,k;
scanf("%d",&t);
for(i=1;i<=t;i++)
scanf("%d",&a);
for(i=1;i<t;i++)
{
s=abs(a[i+1]-a);
b[s]=1;
}
for(i=1;i<t;i++)
{
if(b==0||b>=t)
{
printf("Not jolly\n");
break;
}
if(i==t-1)
printf("Jolly\n");
}
return 0;
}
Re: 10038 - Jolly Jumpers
Posted: Mon Apr 14, 2014 5:19 pm
by ultima_key
Code: Select all
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
inline void fastRead_int(ll &x) {
register ll c = getchar();
x = 0;
ll neg = 0;
for(; ((c<48 || c>57) && c != '-'); c = getchar());
if(c=='-') {
neg = 1;
c = getchar();
}
for(; c>47 && c<58 ; c = getchar()) {
x = (x<<1) + (x<<3) + c - 48;
}
if(neg)
x = -x;
}
int main(){
int c;
while(cin >> c){
if(!c) break;
ll jo[c];
for(int i = 0; i < c; i++) fastRead_int(jo[i]);
bool jolly = true;
map<int, ll> l;
for(int i = 0; i < c-1; i++){
if(abs(jo[i] - jo[i+1]) < c){
if(l[abs(jo[i] - jo[i+1])] == 0) l[abs(jo[i] - jo[i+1])]++;
else{
jolly = false;
break;
}
}
}
if(jolly) cout << "Jolly" << endl;
else cout << "Not jolly" << endl;
}
}
I don't know what is wrong with my code because it gives the correct output but still gets a WA Verdict. Can someone please help me?
Re: 10038 -Jolly jumper. getting WA
Posted: Mon Apr 14, 2014 8:20 pm
by brianfry713
Don't double post
Re: 10038 why getting WA
Posted: Mon Apr 14, 2014 9:56 pm
by brianfry713
You need to keep reading test cases until the end of file.
Re: 10038 - Jolly Jumpers
Posted: Mon Apr 14, 2014 10:00 pm
by brianfry713
2 1 1 is Not jolly
Re: 10038 - Jolly Jumpers WA
Posted: Sat Jun 07, 2014 10:27 pm
by refatsardar
Could you please tell me why 1 1 or 1 2 is a jolly.Since it has only one element so that we will not find any difference,then how to check this condition "the absolute values of the difference between successive elements take on all the values 1 through n-1".
I don't understand this things for 1 1 is a jolly.
Re: 10038 - Jolly Jumpers WA
Posted: Sun Jun 08, 2014 10:32 pm
by lbv
refatsardar wrote:Could you please tell me why 1 1 or 1 2 is a jolly. (..)
As the problem statement specifies, a sequence of
n integers is a
jolly jumper if:
- n > 0
- The set of integers formed by the absolute differences of successive elements is the same set as the integers { 1, 2, ..., (n-1) }
As you say, a sequence with
n=1 has no successive elements, so that set is empty. On the other hand, the set
{ 1, ..., 0 } is also empty. Therefore, all the conditions are satisfied, and a sequence with
n=1 is always jolly.
Re: 10038 - Jolly Jumpers WA
Posted: Mon Jun 09, 2014 8:34 am
by refatsardar
Thnaks lbv,got it your point.