10930 - A-Sequence

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

Moderator: Board moderators

Re: 10930 - A-Sequence

Postby kantaki » Mon Aug 11, 2008 3:29 am

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.
kantaki
New poster
 
Posts: 10
Joined: Tue May 29, 2007 6:18 pm

WA: 10930 - A-Sequence

Postby sazzadcsedu » Wed Feb 11, 2009 9:46 pm

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[i]);

}




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


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

{
sum=seque[i];

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

{
a=seque[i];
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[i]);

}
*/


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

{
r=seque[i];

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

}

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

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

}


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

else

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

ncase++;

}
return 0;

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

Re: 10930 - A-Sequence

Postby stcheung » Sun Aug 23, 2009 9:30 am

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.
stcheung
Experienced poster
 
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am

Re: 10930 - A-Sequence

Postby Jehad Uddin » Thu Oct 08, 2009 2:26 pm

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 ,
Jehad Uddin
Learning poster
 
Posts: 74
Joined: Fri May 08, 2009 5:16 pm

Re: 10930 - A-Sequence

Postby sir. manuel » Sat Nov 20, 2010 9:00 pm

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...
sir. manuel
New poster
 
Posts: 18
Joined: Sat Nov 20, 2010 7:44 pm

Re: 10930 - A-Sequence

Postby DD » Sat Mar 26, 2011 6:53 pm

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. :o
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.
DD
Experienced poster
 
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California

Previous

Return to Volume CIX

Who is online

Users browsing this forum: No registered users and 1 guest