Contest 1 - Hints to Problems [OFFICIAL]

just after taking array,sort the array and reverse then multiply its position+1 ,and then again sort the array and then print the last element.

you sent the problem’s link,share your code’s link,so that i can help you.

hints about Factorial - FCTRL pls

@skcshubham Bigger hint just think in terms of even and odd and you will reach to the solution.

@sah_1403 few hints please try to figure out the formulae with modular arithmetic. If you need explanation please let me know I will help you out.

Thank you.

This is the needed hint !! atleast for me

sort the array first.
then

max_rev=float(’-inf’)
for i in range(0,len(array)):
max_rev=max(array[i]*len(array)-i,max_rev)
print(rev)

@sidhant007 in the document meant to be read here it was given that image

which is oppostie to the hint 1 of the problem MULTHREE

1 Like

SMARTPHONE PROBLEM
CAN ANY ONE TELL ME WHY MY SIMPLE CODE IS NOT PASSING ALL TEST CASE:

long long int T;
cin>>T;
long long int arr[T];
for(int i=0;i<T;i++)
    cin>>arr[i];
sort(arr,arr+T);
long long int n=T/2 +1;
long long int Index=T-n;
long long int price = arr[Index]*n;
cout<<price;
return 0;

PLZ CAN TELL ANY ONE WHY THIS IS NOT WORKING
LADDO PROBLEM

#include
#include<string.h>
using namespace std;

int main() {
long long int test;
cin>>test;
while(test>0)
{
long int rank;
long int laddoo;
long int severity;
long long int activities;
char contest_won[100000];
char top_contributer[100000];
char bug_found[100000];
char contest_host[100000];
char nationality[100000];
cin>>activities;
switch(activities)
{
case 1:
cin>>nationality;
cin>>contest_won;
cin>>rank;
if(rank<20)
{
laddoo=300+(20-rank);
}
else
{
laddoo=300;
}
if(strcmp(nationality,“INDIAN”)==0)
{
cout<<laddoo/200<<"\n";
}
else{

                    cout<<laddoo/400<<"\n";
                }
            break;
        case 2:
            cin>>nationality;
            cin>>contest_won;
            cin>>rank;
            cin>>top_contributer;
            if(rank<20)
            {
                laddoo=300+(20-rank)+300;
                    
            }
            else
            {
                laddoo=300+300;
            }
            if(strcmp(nationality,"INDIAN")==0)
                {
                    cout<<laddoo/200<<"\n";
                }
                else{

                    cout<<laddoo/400<<"\n";
                }

            break;
        case 3:
            cin>>nationality;
            cin>>contest_won;
            cin>>rank;
            cin>>top_contributer;
            cin>>bug_found;
            cin>>severity;
            if(rank<20)
            {

                laddoo=300+(20-rank)+300+severity;

            }
            else
            {
                laddoo=300+300+severity;
            }
            if(strcmp(nationality,"INDIAN")==0)
                {
                    cout<<laddoo/200<<"\n";
                }
            else
            {

                cout<<laddoo/400<<"\n";
            }

            break;
        case 4:
            cin>>nationality;
            cin>>contest_won;
            cin>>rank;
            cin>>top_contributer;
            cin>>bug_found;
            cin>>severity;
            cin>>contest_host;
            if(rank<20)
            {
                laddoo=300+(20-rank)+300+severity+50;
            }
            else
            {
                laddoo=300+300+severity+50;
            }
            if(strcmp(nationality,"INDIAN")==0)
                {
                    cout<<laddoo/200<<"\n";

                }
                else{

                    cout<<laddoo/400<<"\n";
                }
            break;
        default:
        break;
        }


    test--;
}
return 0;

}

Can someone please explain me for the FACTRL problem
a). we are not given the factorial, but a single positive integer, am I right?
b). if answer to a is NO, then why is it that we cannot calculate factorial(assuming a small number < 10) -> convert the number to a decimal and count 0? or is this a stupid solution?
c). I am not sure why the hint says to calculate prime factors? Can someone explain this to me please?

My code for MULTHREE, getting the expected output but shows a WA. Are there any logical errors?

     #include <iostream>
    #include <math.h>

   using namespace std;

  int main()
 {
     int t;
     cin>>t;	    
      while(t--){
    long long int n;
 	cin>>n;
 	int a,b;
 	cin>>a>>b;
 	if(n==2)
 	{
 		if((a+b)%3==0)
 			printf("YES\n");
 		else
 			printf("NO\n");

 		goto end;
 	}
 	else{
 	long long int w = n-3;
 	long long int sum = a + b + ((a+b)%10) + 20*(w/4);
    int z = w%4;
    while(z!=0)
    {
    	sum = sum + sum%10;
    	z--;
    }
     if(sum%3==0)
      {
      	printf("YES\n");
      	goto end;
      }
      else
      {
      	printf("NO\n");
      	goto end;
      }
      
    }
   end:;
  }
  }

Can anyone help me why my code is getting WA?
https://www.codechef.com/viewsolution/33561628
Thanks in advance…

in your solution if input=‘aacaab’ it will give yes

No, it is giving ‘NO’, I have checked it.

sorry i meant aacabb

1 Like

Thanks bro .You are right. :+1: :+1:

for multiple of 3 i cant find what is wrong when submitted it gives wrong answer
https://www.codechef.com/viewsolution/33572022

Please admin help me…I’m unable to understand my mistake in the code…Have been trying this for hours but didn’t get what’s wrong…please help.

#include
#include
using namespace std;

void print(long long int total)
{
if(total % 3 == 0)
cout<<“YES”<<endl;
else
cout<<“NO”<<endl;
}

int main()
{
int test;
cin>>test;

while(test--)
{
    long long int k;
    int d0,d1;                               // variables

    cin>>k>>d0>>d1;
    int sum = d0 + d1;                      // inputs
    long long int total = sum;


    if(sum == 10 || sum == 5)              // for sum 5 and sum 10
    cout<<"NO"<<endl;

    else if(sum == 1 || sum == 3 || sum == 7 || sum == 9)
    {
        long long int new_k = k-3;
        long long int q = new_k / 4;
        long long int r = new_k % 4;

        total += sum + q*20;
        
        for (int i=1; i<=r; i++)
        {
            int power = pow(2,i) ;
            total += ( power * sum ) % 10;
        }
        
        print(total);
        
    }


    else if(sum == 2 || sum == 4 || sum == 6 || sum == 8)
    {
        long long int new_k = k-2;   
        long long int q = new_k / 4;
        long long int r = new_k % 4;
        total += q*20;
        
        for (int i=1; i<=r; i++)
        {
            int power = pow(2,i-1) ;
            total += ( power * sum ) % 10;
        }
        
        print(total);

    }


}

return 0;

}

1 Like

[quote=“sidhant007, post:1, topic:59498, full:true”]
Hints for Contest 1 problems:

The idea and motivation behind these hints is that you should only open them up after spending a decent amount of trying to solve the problem yourself. Also open the hints in sequential order.

Example: Try the problem for 40 mins, then open hint 1. Then using hint 1 only, try the problem for another 20-30 minutes. If still unable to make much progress only, then open hint 2 and so on.

The benefit of knowing a partial solution rather than the complete solution is that you can work out the later stages of the problem yourself, thus improving your problem solving skills.

TLDR; use the hints cautiously, if you start relying on them too much, it can hamper with your learning process.

  1. Lapindromes - LAPIN
Hint 1

Store how many times the letter ‘a’ comes on the left side, how many times the letter ‘b’ comes on the left side and so on, in an array. Do the same for the right side too. Then compare.

  1. Factorial - FCTRL
Hint 1

2s and 5s in prime factorisation of n! matter.

Hint 2

Count only the number of 5s in prime factorisation of n!

Hint 3

\left \lfloor{\frac{n}{5}}\right \rfloor gives the number of numbers \leq n, that have at least one 5 in their prime factorisation, \left \lfloor{\frac{n}{5^2}}\right \rfloor gives the number of numbers \leq n, that have at least 5^2 in their prime factorisation, generalise this idea.

  1. Smart Phone - ZCO14003
Hint 1

The final answer is the form A \times B, where A is the price of the app fixed and B is the number of people willing to buy at that price. We’ve seen people get WA because they only maximise A or only maximise B. (Eg. I will make price 1 so everyone will buy, or I will make price very high, but very few people will buy)

Hint 2

Sort all the people by the budgets

Hint 3

If the sorted budget array looks like this = [2, 10, 15, 23]
Then trying to fix the price at 10 is always better than trying to fix the price at 9, because in both cases exactly 3 people will buy at the given price.
That is you only need to try some candidate solutions and not all of them.

  1. Multiple of 3 - MULTHREE
Hint 1

Find a pattern and beware of an incorrect approach, i.e (d_0 + d_1 + d_2 + … + d_n) \mod 10 \neq (d_0 \mod 10 + d_1 \mod 10 + d_2 \mod 10 + … + d_n \mod 10)

Hint 2

d_2 = (d_0 + d_1) \mod 10, d_3 = 2(d_0 + d_1) \mod 10, d_k = 2^{k - 2}(d_0 + d_1) \mod 10

Hint 3

2^1 \mod 10 \equiv 2, 2^2 \mod 10 \equiv 4, 2^3 \mod 10 \equiv 8, 2^4 \mod 10 \equiv 6, 2^5 \mod 10 \equiv 2, 2^6 \mod 10 \equiv 4, … can see the cycling nature of powers of 2 under modulo 10

[/quote]