Contest 1 - Hints to Problems [OFFICIAL]

For Laddu, why is this approach is not working ?

#include<stdio.h>
#include<string.h>
int main(void)
{
int t;
scanf("%d",&t);
while(t–)
{
int activities;
char origin[16];
scanf("%d%s",&activities,origin);

	int max_amount=0;

	while(activities--)
	{
		int amount=0;

		char activity[16];
		scanf("%s",activity);

		if(strcmp(activity,"CONTEST_WON")==0)
		{
			int rank;
			scanf("%d",&rank);

			amount = 300 + 20 - rank;

			if(rank>20)
				amount = amount - 20 - rank;

		}

		if(strcmp(activity,"TOP_CONTRIBUTOR")==0)
			amount = 300;

		if(strcmp(activity,"BUG_FOUND")==0)
		{
			int severity;
			scanf("%d",&severity);

			amount = severity;
		}

		if(strcmp(activity,"CONTEST_HOSTED")==0)
			amount = 50;

		max_amount = max_amount + amount;
	}

	if(strcmp(origin,"INDIAN")==0)
		max_amount = max_amount/200;
	else
		max_amount = max_amount/400;

	printf("%d\n",max_amount);
}
return 0;

}

I am doing the same, but still getting WA. Can tell any corner case to take care about?

Here you have to check for bonus (20-rank) to be positive, then add it to total laddus, here your math is going wrong.

It should be something like this -

Or you can build your own math to get it done in any way.

1 Like

can anyone suggest what is wrong in the following code(multhree):

int main() {
// your code goes here
int t;
cin>>t;
while(t–){
long long k;
int d0,d1;
cin>>k>>d0>>d1;
if(k==2){
if((d0+d1)%3==0){
cout<< “YES” << “\n”;
continue;
}
else{
cout<< “NO” << “\n”;
continue;
}
}
int sum=(d0+d1);
int d2=sum%10;
int previous_sum= d0+d1+d2;
long long cycles= (k-3)/4;
long long cycles_sum= ((2sum%10)+(4sum%10)+(8sum%10)+(6sum%10))*cycles;
int left_over_terms=(k-3)%4;
int total_sum= previous_sum+cycles_sum;
for(auto i=1; i<=left_over_terms; i++){
total_sum+=(1<<i)*sum%10;
}
if(total_sum%3==0)
cout<< “YES”<< “\n”;
else
cout<< “NO”<< “\n”;
}
return 0;
}

Thanks for the reply!!!

Can you format your code or share a link to your source-code using pastebin.

P.S. You can refer to the this post: Code-Chef DSA Series-1 Editorial.

import java.util.;
import java.lang.
;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t–>0)
{
String s=sc.next();
int l=s.length();
int k=0;
int c=0;
if(l%2==0)
{
for(char ch=‘a’;ch<=‘z’;ch++)
{
System.out.println(ch);
for(int i=0;i<l;i++)
{
if(s.charAt(i)==ch)
c++;
}
if(c%2==0)
{
k++;
}
c=0;

	        }
	        if(k*2==l)
	        System.out.println("YES");
	        else
	        System.out.println("NO");
	    }
	    else
	    {
	        for(char ch='a';ch<='z';ch++)
	        {
	            for(int i=0;i<l;i++)
	            {
	                if(i==l/2)
	                continue;
	                if(s.charAt(i)==ch)
	                c++;
	            }
	            if(c%2==0)
	            {
	                k++;
	            }
	            c=0;
	            
	        }
	        if(k*2==l-1)
	        System.out.println("YES");
	        else
	        System.out.println("NO");
	    }
	}
}

}
This is my code for LAPIN problem , it seems right but for every test case the answer is NO . Can anyone help me out?

#include <bits/stdc++.h>
using namespace std;

int main() {
// your code goes here
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t–){
int i=1,val,k,a,b,sum=0,res=0;
cin>>k>>a>>b;
res=(k-2)%4;
for(int j=1;j<=res;j++)
i*=2;
if(res==0&&k>2)
i=6;
val=i*(a+b);
//cout<<val;
if(val%3==0)
cout<<“YES\n”;
else
cout<<“NO\n”;}
}
Can someone please tell me what is wrong in this sol for ques MULTHREE

Fixed :slight_smile:

for problem Factorial this article will help you How to Find Number of Trailing Zeros in a Factorial or Product | Handa Ka Funda - Online Coaching for CAT and Banking Exams

Hey, it’s a completely pattern based question. Very very easy. Search the pattern, very simple pattern.

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;