11775 - Unique Story

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

Moderator: Board moderators

Post Reply
Mehadi
New poster
Posts: 18
Joined: Sun Jan 24, 2010 11:17 am

11775 - Unique Story

Post by Mehadi »

Can Any one PLZ Help me.My Code is here.Can Any one give me any critical input output.

Code: Select all

#include<iostream>
#include<cstring>

using namespace std;
char P[1001][1001],Q[1001][1001];
long c[3001][3001],b[3001][3001],p;

// ******************
void LCS(long x1,long y1)
{
	long i,j,m,n,last;
	m=x1;
	n=y1;p=0;

	for(i=1;i<=m;i++)
		c[i][0]=0;

	for(i=0;i<=n;i++)
		c[0][i]=0;

	for(i=1;i<=m;i++)
	{
		last=0;
		for(j=1;j<=n;j++)
		{
			if(!strcmp(P[i-1],Q[j-1]))
			{
				c[i][j]=c[i-1][j-1]+1;
				b[i][j]=1;last=1;
			}
			else if(c[i-1][j]>=c[i][j-1])
			{
				c[i][j]=c[i-1][j];
				b[i][j]=2;
			}
			else
			{
				c[i][j]=c[i][j-1];
				b[i][j]=3;
			}
		}
		p+=last;
	}
}

// *********************
long bigmode(long ba,long pa,long ma)
{

	long x;
	if(pa==0)
		return 1;
	else if(pa%2==0)
	{
		x=(bigmode(ba,pa/2,ma))%ma;
		return x*x;
	}
	else
	{
		return ((ba%ma)*bigmode(ba,pa-1,ma))%ma;
	}
}


int main()
{
	char x[3001],y[3001],temp[3001];
	long n,i,k,l=1,sum,one,two,three,flag,x1,y1;
	scanf("%ld",&n);
	while(n)
	{
		p=0;
		scanf("%s%s",x,y);
		x1=0;y1=0;k=0;
		flag=0;k=0;one=0;

		for(i=0;x[i]!='\0';i++)
		{
			if(x[i]>='A'&&x[i]<='Z'&&flag)
			{				
				temp[k]='\0';
				strcpy(P[one++],temp);
				k=0;
				temp[k++]=x[i];
			}
			else
			{
				if(x[i]>='A'&&x[i]<='Z'||flag)
				{
				temp[k++]=x[i];
				flag=1;
				}
			}
		}
		temp[k]='\0';
		strcpy(P[one++],temp);

		x1=one;

		flag=0;k=0;one=0;
		for(i=0;y[i]!='\0';i++)
		{
			if(y[i]>='A'&&y[i]<='Z'&&flag)
			{				
				temp[k]='\0';
				strcpy(Q[one++],temp);
				k=0;
				temp[k++]=y[i];
			}
			else
			{
				if(y[i]>='A'&&y[i]<='Z'||flag)
				{
				temp[k++]=y[i];
				flag=1;
				}
			}
		}
		temp[k]='\0';
		strcpy(Q[one++],temp);
		
		y1=one;
		
	
		if(x1!=0 && y1!=0)
		{
			LCS(x1,y1);
			k=p;
		}
		else
			k=0;
		if(x1==y1 && y1==k)
		{
			printf("Case %ld: 0\n",l++);
		}
		else
		{
			sum=0;
			one=0;two=0;three=0;
		if(x1!=0)
			one=(bigmode(2,x1,10000007)-1);
		if(y1!=0)
			two=(bigmode(2,y1,10000007)-1);
		if(k!=0)
			three=(bigmode(2,k,10000007)-1);
		
		sum=(one-three)+(two-three);

		printf("Case %ld: %ld\n",l++,sum);
		}
		n--;
	}

	return 0;
}
Nahiyan Kamal
New poster
Posts: 7
Joined: Sat Apr 04, 2009 6:40 pm

Re: WA:11775(Unique Story)

Post by Nahiyan Kamal »

in your code
in bigmode function
you have declared long
but return x*x;
this might be very big.
this is an error. you need long long here iguess


another mistake i believe is in your algorithm
what will be the output in this case:
1
A1B1
B1A1

i think there are two unique sequences A1B1 B1A1
but yours gives 0
Last edited by Nahiyan Kamal on Thu May 06, 2010 9:20 am, edited 2 times in total.
Post Reply

Return to “Volume 117 (11700-11799)”