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

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

Re: 10930 why RE??

Post by cse.mehedi »

brianfry713 wrote:Don't print a space at the end of the sequence.
Again WA!!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10930 why RE??

Post by brianfry713 »

Post your updated code.
Check input and AC output for thousands of problems on uDebug!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10930 why RE??

Post by brianfry713 »

This code doesn't compile, you're missing the { after main().
Check input and AC output for thousands of problems on uDebug!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10930 why RE??

Post by brianfry713 »

Input: 2 2 1
is not an A-sequence.

Add a post when you update your code.
Check input and AC output for thousands of problems on uDebug!
tridorje
New poster
Posts: 8
Joined: Wed Oct 02, 2013 3:23 am

10930 Wa :(

Post by tridorje »

remove
Last edited by tridorje on Wed Nov 13, 2013 5:37 am, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10930 why RE??

Post by brianfry713 »

brianfry713 wrote:Input: 2 2 1
is not an A-sequence.
Check input and AC output for thousands of problems on uDebug!
tridorje
New poster
Posts: 8
Joined: Wed Oct 02, 2013 3:23 am

Re: 10930 why RE??

Post by tridorje »

brianfry713 wrote:
brianfry713 wrote:Input: 2 2 1
is not an A-sequence.
Thank Brianfry :)
AbdAllah Boda
New poster
Posts: 6
Joined: Sat Dec 01, 2012 2:52 pm

Re: 10930 - A-Sequence

Post 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 ?
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10930 - A-Sequence

Post 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.
Check input and AC output for thousands of problems on uDebug!
AbdAllah Boda
New poster
Posts: 6
Joined: Sat Dec 01, 2012 2:52 pm

Re: 10930 - A-Sequence

Post by AbdAllah Boda »

@ brianfry713: thanx man, i've finally solve it, but i used a Backtracking method :D
thanx again ..
richatibrewal
New poster
Posts: 49
Joined: Mon Jun 16, 2014 7:40 pm

Re: 10930 - A-Sequence

Post 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;
}
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10930 - A-Sequence

Post 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.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
BlackBeard
New poster
Posts: 18
Joined: Wed Dec 17, 2014 9:44 pm

Re: 10930 - A-Sequence

Post 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;
}
Post Reply

Return to “Volume 109 (10900-10999)”