Had tried it.
Hi @sidhant007 can you look at my code and help me find the bug. For test cases it gives right output but when I submit it says WA.
https://www.codechef.com/viewsolution/31080908
In your code
if(((k-3)%4)==1)
{sum+=a;}//cout<<"here"<<a<<endl;
else if(((k-3)%4)==2)
{sum+=a+b;}//cout<<"1"<<endl;}
else
{sum+=a+b+c;}
This is the buggy part, in the else you add a + b + c, even if (k - 3) % 4 == 0
Thanks a lot Sidhant, I found it late in the night and had submitted it. Thanks a lot for responding.
HEY @sidhant007 can you please help me find the bug in this.
trying since 3 dayshttps://www.codechef.com/LRNDSA01/submit/ZCO14003
On which array are you binary searching on? If you are applying binary search then, the array is already sorted and the last element will be the max.
Review your logic once more, I guess.
Hope this helps.
hints for the caravans problem
In Hint 3 of FCTRL
shouldn’t it be n/5 instead of n!/5
There is a pattern in answer itself…find that if didn’t find till now
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.
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
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.