RGAME - Editorial

lol i am new :stuck_out_tongue:

somebody please upvote me , i have questions to ask
thank you

2 Likes

Hmm, I need some amount of help. I have written the code, which seems to work right for a small number of elements. When we increase the size of the elements, then it makes a small mistake somehow. The test case I ran, had an error of -19. I want to know where is this error generated.
Here is the code : CodeChef: Practical coding for everyone

can any one tell why i m getting wrong ans for this method

https://www.codechef.com/viewsolution/12137512

I have written this code for the given problem but for some reason, while submitting, it’s giving me some error. Can anyone please help me with this? By the way, it was a good problem.
#include<stdio.h>
struct code
{
int y;
int a[100][2];
int b[100];
int k;
}grp[100];
int arr[100],t,n,kk,j,p,c,a,i,z,m,sum=0;
void main()
{
for(i=0;i<100;i++)
{
grp[i].k=0;
}
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&n);
for(j=0;j<=n;j++)
{
scanf("%d",&kk);
arr[j]=kk;
z=0;
if(j!=0)
{
p=grp[j-1].k;
for(c=0;c<=p;c++)
{
grp[j].a[z][0]=j;
grp[j].a[z][1]=grp[j-1].a[c][1];
grp[j].b[z]=grp[j-1].b[c]+arr[grp[j-1].a[c][0]]*arr[j];

				z++;
				grp[j].a[z][0]=grp[j-1].a[c][0];
				grp[j].a[z][1]=j;
				grp[j].b[z]=grp[j-1].b[c]+arr[grp[j-1].a[c][1]]*arr[j];
				
				z++;
			}
			z=z-1;
			grp[j].k=z;
		}
		else
		{
			grp[j].k=0;
			grp[j].b[0]=0;
			grp[j].a[0][0]=0;
			grp[j].a[0][1]=0;
		}	
	}
	j--;
	for(m=0;m<=grp[j].k;m++)
	{
		sum+=grp[j].b[m];
	}		
	printf("%d\n",sum);
	sum=0;
}

}

#include<stdio.h>
struct code
{
int y;
int a[100][2];
int b[100];
int k;
}grp[100];
int arr[100],t,n,kk,j,p,c,a,i,z,m,sum[100];
void main()
{
for(i=0;i<100;i++)
{
grp[i].k=0;
}
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&n);
for(j=0;j<=n;j++)
{
scanf("%d",&kk);
arr[j]=kk;
z=0;
if(j!=0)
{
p=grp[j-1].k;
for(c=0;c<=p;c++)
{
grp[j].a[z][0]=j;
grp[j].a[z][1]=grp[j-1].a[c][1];
grp[j].b[z]=grp[j-1].b[c]+arr[grp[j-1].a[c][0]]*arr[j];

				z++;
				grp[j].a[z][0]=grp[j-1].a[c][0];
				grp[j].a[z][1]=j;
				grp[j].b[z]=grp[j-1].b[c]+arr[grp[j-1].a[c][1]]*arr[j];
				
				z++;
			}
			z=z-1;
			grp[j].k=z;
		}
		else
		{
			grp[j].k=0;
			grp[j].b[0]=0;
			grp[j].a[0][0]=0;
			grp[j].a[0][1]=0;
		}	
	}
	j--;
	for(m=0;m<=grp[j].k;m++)
	{
		sum[i]+=grp[j].b[m];
	}		
}
for(i=0;i<t;i++)
	printf("%d\n",sum[i]);

}
Please tell me what’s the problem in this code. It’s running fine in my compiler.

@jawa2code @killjee please help make this solution perfect.
#include<stdio.h>
struct code
{
int y;
int a[100][2];
int b[100];
int k;
}grp[100];
int arr[100],t,n,kk,j,p,c,a,i,z,m,sum[100];
void main()
{
for(i=0;i<100;i++)
{
grp[i].k=0;
}
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&n);
for(j=0;j<=n;j++)
{
scanf("%d",&kk);
arr[j]=kk;
z=0;
if(j!=0)
{
p=grp[j-1].k;
for(c=0;c<=p;c++)
{
grp[j].a[z][0]=j;
grp[j].a[z][1]=grp[j-1].a[c][1];
grp[j].b[z]=grp[j-1].b[c]+arr[grp[j-1].a[c][0]]*arr[j];

				z++;
				grp[j].a[z][0]=grp[j-1].a[c][0];
				grp[j].a[z][1]=j;
				grp[j].b[z]=grp[j-1].b[c]+arr[grp[j-1].a[c][1]]*arr[j];
				
				z++;
			}
			z=z-1;
			grp[j].k=z;
		}
		else
		{
			grp[j].k=0;
			grp[j].b[0]=0;
			grp[j].a[0][0]=0;
			grp[j].a[0][1]=0;
		}	
	}
	j--;
	for(m=0;m<=grp[j].k;m++)
	{
		sum[i]+=grp[j].b[m];
	}		
}
for(i=0;i<t;i++)
	printf("%d\n",sum[i]);

}

Please tell me what is wrong with this solution in the below given link :

https://www.codechef.com/viewsolution/12927725

While submitting my solution for this problem, I am getting compile error and if I click on the link to find out what the compilation error is, then I am getting to a page where it says ‘There was an error while serving this page. Please try again after some time’. Is there anyone who faced a similar issue? Any ideas?

hello,
i don’t understand the solution of 121 even after reading the editorial.
in the explanation of the of the answer for 121 i’ve read the solution to be adding the sum of scores of gameplays taking 121 twice. According to the problem, two gameplays are different if after writing down all the numbers, the sequences of the gameplays aren’t identical.
for this to be true, 121 has only three gameplays - 121, 112 and 211. these gameplays gave the answer as 12+21 = 4, 11+12 = 3 and 21+11 = 3. This gives an answer of 10. Now, in other explanations the 121 gameplay has been taken twice - once by doing this sequence - 12 -> 1 -> 121 - and the other by doing 21 -> 1 (on the front end) -> 121. In the end, this gameplay can not be taken as two different gameplays as both of them result in the same sequence after writing down (n+1) numbers. So, what’s the explanation for the answer?

Hello, can someone please tell me what’s wrong with my code-
It is giving right answers for Subtask 1
But giving wrong answer(WA) for Subtask 2
And for Subtask 3, it is giving TLE(As the complexity of my code is O(n^2)),
Please tell me why it is giving WA for Subtask 2?

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#define MOD 1000000007
#define ull unsigned long long int
using namespace std;

ull multiply(ull a,ull b)
{
	ull mul=(a%MOD*b%MOD)%MOD;
	return(mul);
}

int main()
{
    ull test;
    cin>>test;
    while(test)
    {
        int n;
        cin>>n;
        ull arr[n+1];
        ull sum=0,mul=1,exp=1;
        for(int i=0;i<=n;i++)
        {
            cin>>arr[i];
        }
        for(int i=1;i<=n;i++)
        {
            exp=multiply(exp,2);
        }
        for(int i=0;i<n;i++)
        {
            ull k=exp;
            if(i!=0)
                k=exp/2;
            for(int j=i+1;j<=n;j++)
            {
                mul=multiply(multiply(arr[i],arr[j]),k);
                sum=(sum%MOD+mul%MOD)%MOD;
                k=k/2;
            }
        }
        cout<<sum<<endl;
        test--;
    }
}

Hey can any one check my code also? I am getting correct answer for subtask one but wrong for other two.
check my code:

#include<iostream>
using namespace std;
long long int M=1000000007;
unsigned long long int power(long long int n)
{
unsigned	long long sum=1;
	for(long long int i=0;i<n;i++)
	sum=(sum*2)%M;
	return sum;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
	unsigned	long long int n,a[100010],i,j,sum=0,tot,tot2,pdt1,pdt2;
		cin>>n;
		n=n+1;
		for(int i=1;i<=n;i++)
		cin>>a[i];
	for(i=1;i<=n-1;i++)
	{
		if(i==1||i==2)
		tot=2;
		
		else tot=(tot*2)%M;
		pdt1=(a[i]*tot)%M;
		
	//cout<<tot<<endl;
	for(j=i+1;j<=n;j++)
	{

	if(j==i+1)
	tot2=mult(n-j)%M;
	else tot2=tot2/2;
	pdt2=(a[j]*tot2)%M;
	
	//	cout<<tot<<endl;
		sum=(sum+(pdt1*pdt2)%M)%M;
		//cout<<sum<<endl;
	
	}
}
	cout<<sum<<endl;	
	}
	return 0;
}

I have slightly easier approach. We can visualize the problem with reference to a binary tree. Starting from the top-most part of the node we can draw a binary tree in such a way that the new number goes to the left of the previous numbers in the left sub-tree and it goes to the right of the previous numbers in the right sub-tree. In the way we just have to eliminate the numbers having same sequence. This is depicted in the below link:
https://drive.google.com/file/d/0B9d_mf_aoiYAUUttdDZmOXc1Z2M/view?usp=sharing

In this image we can calculate the sum at each levels of the tree i.e. 12=2,21=2,121=4,211=3,112=3. Total is 14. We can ignore the last element of the subtree since it is a repeated sequence. Please upvote my answer if you find this to be helpful. I will put on the code in a short while.

First I’ll say that the percentage success model can be really helpful on this program. You can write a direct-simulation program to solve subtask 1 and with that you can generate test data to support other approaches.

My solution runs forward through the cases by maintaining a term that represents the mix of exposed ends of the game string. This is initially t_0 = 2 a_0 - two sides of the first placement - then t_1 = 2(a_0+a_1), the two exposed ends of the two possible games of n=1 - then t_2 = 2(a_0+a_1) + 4a_2, t_3=2(a_0+a_1) + 4a_2 +8a_3, etc. Each time the next move set sums across all possibilities to s_k = a_k t_{k-1}, with the accumulated game score also including twice the sum of previous game scores, g_k = 2g_{k-1} + s_k since there are two possibilities for this move.

The initial problem statement had this confusion. It was updated on 2nd or 3rd day as far as i remember

–> “when we read from left to right, there exists some position i, at which the gameplays have aj and ak written at the ith position such that j ≠ k.”

		1	2			2
		1	2	1		2
		1	2			2
	1	1	2			1
	2	1				2
1	2	1				2
	2	1				2
	2	1	1			1

					sum 14		

Hi, what is the issue with this one? Up to 5 digits, compared my answers actual and it shows no difference. However, after 5 digits answers do not match.
Here’s the code link

Hi, Im having trouble understanding the second approach mentioned in the editorial are there any other resources so that I can understand easily

Thanks in advance

best one sir

why we are calculating 121 twice ???