Page 7 of 7

Re: 10930 why RE??

Posted: Fri Apr 13, 2012 12:46 am
by cse.mehedi
brianfry713 wrote:Don't print a space at the end of the sequence.
Again WA!!

Re: 10930 why RE??

Posted: Tue Apr 17, 2012 1:10 am
by brianfry713
Post your updated code.

Re: 10930 why RE??

Posted: Tue Apr 17, 2012 10:39 pm
by brianfry713
This code doesn't compile, you're missing the { after main().

Re: 10930 why RE??

Posted: Wed Apr 18, 2012 11:38 pm
by brianfry713
Input: 2 2 1
is not an A-sequence.

Add a post when you update your code.

10930 Wa :(

Posted: Sun Nov 10, 2013 11:29 am
by tridorje
remove

Re: 10930 why RE??

Posted: Wed Nov 13, 2013 1:29 am
by brianfry713
brianfry713 wrote:Input: 2 2 1
is not an A-sequence.

Re: 10930 why RE??

Posted: Wed Nov 13, 2013 5:36 am
by tridorje
brianfry713 wrote:
brianfry713 wrote:Input: 2 2 1
is not an A-sequence.
Thank Brianfry :)

Re: 10930 - A-Sequence

Posted: Mon Dec 02, 2013 7:03 am
by AbdAllah Boda
1 TL and 8 WA ..

and i can't find why :@ ..
does arr[1] MUST BE 1 or it just have to be increasingly-ordered ?

that's my code ..

Code: Select all

//WA :(

#include <iostream>
#include <map>
using namespace std;

bool A_Seq;
int Size;
int arr[35];

void Dispaly_arr()
{
	for (int i = 0; i < Size; ++i)
	{
		cout << arr[i];
		if (i != Size - 1) cout << " ";
	}
	cout << endl;
}

int main ()
{
	//freopen ("in.txt", "r", stdin);
	//freopen ("out.txt", "w", stdout);
	int T = 0;

	while (cin >> Size)
	{
		map <int, int> Sums;
		A_Seq = true;
		for (int i = 0; i < Size; ++i)
		{
			cin >> arr [i];
			if ((i && arr [i] <= arr [i-1]) || arr [i] < 1) A_Seq = false;
			else Sums[arr[i]] = 1;
		}
		//if (arr[0] != 1) A_Seq = false;
		if (A_Seq) 
		{
			for (int i = 0; i < Size; ++i)
			{
				for (int j = i+1; j < Size; ++j)
				{
					int sum = arr[i]+arr[j];
					++Sums[sum];
					if (Sums[sum] > 1)
					{
						A_Seq = false;
						break;
					}
				}
				if (!A_Seq) break;
			}
		}
		//Case #2: 1 2 3
		cout << "Case #"<<++T<<": ";
		Dispaly_arr();
		if (A_Seq) cout << "This is an A-sequence." << endl;
		else cout << "This is not an A-sequence." << endl;
	}

	return 0;
}

any help ?

Re: 10930 - A-Sequence

Posted: Wed Dec 04, 2013 2:45 am
by brianfry713
Input:

Code: Select all

4 2 3 7 8
AC output:

Code: Select all

Case #1: 2 3 7 8
This is an A-sequence.

Re: 10930 - A-Sequence

Posted: Fri Dec 06, 2013 7:45 pm
by AbdAllah Boda
@ brianfry713: thanx man, i've finally solve it, but i used a Backtracking method :D
thanx again ..

Re: 10930 - A-Sequence

Posted: Sat Oct 11, 2014 11:24 am
by richatibrewal
Hiii, I m getting wrong ans continuosly. I have checked the output for all the previous inputs given in the board and and i m getting the expected output. plz help
Thanx

Code: Select all

#include<cstdio>
using namespace std;
int sequence(int a[],int n)
{
    int i,j,k,sum;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            sum=a[i]+a[j];
            if(sum==a[n])
                return 0;
            for(k=j+1;k<n;k++)
            {
                if(sum+a[k]>a[n])
                    break;
                else sum=sum+a[k];
                if(sum==a[n])
                    return 0;
            }
        }
    }
    return 1;
}
int main()
{
    int d,i,arr[40],flag,c=0;
    while(scanf("%d",&d)==1)
    {
        c++;
        flag=1;
        for(i=0;i<d;i++)
        {
            scanf("%d",&arr[i]);
            if(i!=0)
                if(arr[i]<=arr[i-1])
                    flag=0;
        }
        if(flag)
        {
            for(i=0;i<d;i++)
            {
                flag=sequence(arr,i);
                if(flag==0)
                    break;
            }
        }
        printf("Case #%d:",c);
        for(i=0;i<d;i++)
            printf(" %d",arr[i]);
        if(flag)
            printf("\nThis is an A-sequence.\n");
        else
            printf("\nThis is not an A-sequence.\n");
    }
    return 0;
}

Re: 10930 - A-Sequence

Posted: Mon Oct 13, 2014 5:23 pm
by lighted
Input

Code: Select all

6 1 2 5 10 14 21
7 1 2 5 10 14 23 36
Acc Output

Code: Select all

Case #1: 1 2 5 10 14 21
This is not an A-sequence.
Case #2: 1 2 5 10 14 23 36
This is not an A-sequence.
Got accepted now by DP. Then I read posts in this thread. Some people misunderstood problem description. There is no need in sorting. If input is not sorted we should print that it is not A-sequence. Else check for sums.

Re: 10930 - A-Sequence

Posted: Sat May 21, 2016 1:34 pm
by BlackBeard
I've tried every possible input from here and udebug. Still getting WA. No idea what's wrong. Help me...
Here's the code....

Code: Select all

#include<bits/stdc++.h>
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define scs(x) scanf("%s",x)
#define pr(x) printf("%d",x)
#define prn(x) printf("%d\n",x)
#define memc(x,y) memcpy(&x,&y,sizeof(x))
#define mems(x,y) memset(x,y,sizeof(x))
#define fli() freopen("in.txt","r",stdin)
#define flo() freopen("out.txt","w",stdout)
#define rep(i,v) for(int i=0;i<v;i++)
#define repe(i,v) for(int i=0;i<=v;i++)
#define Rep(i,x,v) for(int i=x;i<v;i++)
#define Repe(i,x,v) for(int i=x;i<=v;i++)
#define repv(i,x) for(auto i=x.begin();i!=x.end();i++)
#define reprv(i,x) for(auto i=x.rbegin();i!=x.rend();i++)
#define what_is(x) cerr << #x << " : " << x << endl
#define pb push_back
#define bl putchar('\n')
#define gcc getchar()
#define pcc putchar
#define si size
#define fi first
#define se second
#define MAX 1010
typedef long long ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::pair<int,int> ii;
using namespace std;

int a[35],idx,sum[MAX],tidx,tsum[MAX];
bool dp[MAX];

int main(){
//    fli();
//    flo();
    int n,test_no=1;
    bool flag;
    while(sc(n)==1){
        flag=true;
        printf("Case #%d:",test_no++);
        rep(i,n){
            sc(a[i]);
            printf(" %d",a[i]);
            if(i and a[i]<=a[i-1]){
                flag=false;
            }
        }bl;
        if(a[0]<1) flag=false;
        mems(dp,0);
        mems(sum,0);
        idx=0;
        rep(i,n){
            if(dp[a[i]] or !flag){
                flag=false;
                break;
            }
            tidx=0;
            rep(j,idx){
                if(a[i]+sum[j]<=1000){
                    dp[a[i]+sum[j]]=1;
                    tsum[tidx++]=a[i]+sum[j];
                }
            }
            sum[idx++]=a[i];
            dp[a[i]]=1;
            rep(j,tidx){
                sum[idx++]=tsum[j];
            }
        }
        if(flag){
            puts("This is an A-sequence.");
        }else{
            puts("This is not an A-sequence.");
        }
    }
    return 0;
}