## 10930 - A-Sequence

All about problems in Volume 109. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

Input:

Code: Select all

``````6 46 25 73 71 30 78
2 15 25``````
Output:

Code: Select all

``````Case #1: 46 25 73 71 30 78
This is not an A-sequence.
Case #2: 15 25
This is an A-sequence.``````
Hope these help.
Ami ekhono shopno dekhi...
HomePage

kantaki
New poster
Posts: 10
Joined: Tue May 29, 2007 6:18 pm

### Re: 10930 - A-Sequence

I checked previous posted test case, and got correct answer, I thnk.
But I'm still W.A.
What is my problem with my code?
Please help me.

Code: Select all

``````Got AC.
``````
I solve this problem without sorting.
Because of sorting, I got WA.

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

### WA: 10930 - A-Sequence

whats wrong ??
WA.

#include<stdio.h>
#include<memory.h>

int main()

{
int i,j,k,d,sum,a,b,c,rem,r,flag,ncase=1;
int array[31000];
int seque[31];

while(scanf("%d",&d)==1)

{

for(i=0;i<d;i++)
{
scanf("%d",&seque);

}

flag=0;
memset(array,0,sizeof(array));

for(i=0;i<d-1;i++)

{
sum=seque;

for(j=i+1;j<d;j++)

{
a=seque;
b=seque[j];
c=a+b;
// printf("%d %d\n",a,b);

array[c]=1;

sum=sum+b;
array[sum]=1;
//printf("in %d and %d c:%d sum:%d\n",i,j,c,sum);

for(k=i+1;k<j;k++)

{
rem=seque[k];

array[sum-rem]=1;
//printf("in %d and %d and k rem:%d\n",i,j,rem);
}

}
}

/* for(i=1;i<=32;i++)
{
printf("i:%d %d\n",i,array);

}
*/

for(i=1;i<d;i++)

{
r=seque;

if(array[r]==1)
flag=1;

}

printf("Case #%d:",ncase);

for(i=0;i<d;i++)
{
printf(" %d",seque);

}

if(flag==1)
printf("\nThis is not an A-sequence.\n");

else

printf("\nThis is an A-sequence.\n");

ncase++;

}
return 0;

}
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

### Re: 10930 - A-Sequence

Just got AC after almost 10 WA. Let me sum up the cases at this point:
(1) If there's duplicate or if the input sequence is NOT in increasing order, then it's NOT an A-sequence. With that said, you do NOT have to sort the input.

(2) Instead of setting the array size as 30000, setting it to 1000 is enough because each number in the input sequence is <= 1000 anyways.

(3) Finally, here's a test input that helps me discover my error:
5 1 10 100 911 1000
My AC code returns "This is an A-sequence." My original error was that when considering the 100, I already know I should reject 11, and so my code would also start rejecting 111, then 211, 311, 411...911 because of the way my loop was (incorrectly) written.

Jehad Uddin
Learning poster
Posts: 74
Joined: Fri May 08, 2009 5:16 pm

### Re: 10930 - A-Sequence

i have got 11 WAs and then got acc,lots of misunderstanding in the board i think, no need to sort the given no, just have to follow it 1 ? a1 < a2 < a3 < ...,if it breaks then its not A-sequence ,

sir. manuel
New poster
Posts: 18
Joined: Sat Nov 20, 2010 7:44 pm

### Re: 10930 - A-Sequence

I think that my algorithm it´s fine, but i got WA. I can´t find my error!!!
Can you help me?

Code: Select all

``````#include<stdio.h>
int main()
{
int tam,n=1;
while(scanf("%d",&tam)==1){
int aux=tam,vec[tam],indice=0,band=1;
while(aux--){
scanf("%d",&vec[indice]);
indice++;
}
if(vec[0]>=1);
else band=0;

for(int i=1;i<tam;i++){
if(vec[i]>vec[i-1]);
else band=0;
}
if(band==1 && tam>=3){
for(int i=2;i<tam;i++){
for(int j=0;j<i;j++){
for(int k=0;k<i;k++){
if(k!=j){
if(vec[j]+vec[k]==vec[i]){band=0; break;}
}
}
}
}
}
printf("Case #%d:",n);
for(int i=0;i<tam;i++)printf(" %d",vec[i]);  puts("");

if(band==1){
puts("This is an A-sequence.");
}
else{
puts("This is not an A-sequence.");
}
n++;
}
return 0;
}
``````
I read many comments for this problem,...,but i think that is not neccesary order the elements of the sequence...
Only have to check that each Ak>A(n) for n=1,2,...,k-1
And do tho fors to check the sum is the same that Ak...

DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

### Re: 10930 - A-Sequence

One of previous test case:

Code: Select all

``3 4 336 34 ``
Timo's A.C. outputs is:

Code: Select all

``````Case #1: 4 336 34
This is an A-sequence.``````
My A.C. output is:

Code: Select all

``````Case #1: 4 336 34
This is not an A-sequence. ``````
I think there is something wrong in Judge's test data.
Have you ever...
• Wanted to work at best companies?
• Struggled with interview problems that could be solved in 15 minutes?
• Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.

cse.mehedi
New poster
Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

### 10930 why RE??

Last edited by cse.mehedi on Thu Apr 19, 2012 7:57 pm, edited 6 times in total.

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

### Re: 10930 why RE??

put this line at the end of your code.
return 0;
Check input and AC output for thousands of problems on uDebug!

cse.mehedi
New poster
Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

### Re: 10930 why RE??

brianfry713 wrote:put this line at the end of your code.
return 0;
i put return 0; but again shows "the execution of your program didn't finish properly. Remember to always terminate your code with the exit code 0."

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

### Re: 10930 why RE??

You are defining arr to have size 0 on it's declaration. The line with just arr[n] doesn't resize the array. There are other issues with your code.
Check input and AC output for thousands of problems on uDebug!

cse.mehedi
New poster
Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

### Re: 10930 why RE??

I modified my code but WA!

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

### Re: 10930 why RE??

Don't read from a file.
Check input and AC output for thousands of problems on uDebug!

cse.mehedi
New poster
Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

### Re: 10930 why RE??

Give me some test case!!

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

### Re: 10930 why RE??

Don't print a space at the end of the sequence.
Check input and AC output for thousands of problems on uDebug!