CATSDOGS - Editorial

O(1) Solution:

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

int main()
{
int t;
cin>>t;
while(t--){
	long long c,d,l,maxlegs,minlegs,cog,flag=0;
	cin>>c>>d>>l;
	if(l%4==0){
		maxlegs=(c+d)*4;
		if(c>2*d){
			cog=c-2*d;
		}
		else cog=0;
		minlegs=(d+cog)*4;
		
		if(l>=minlegs && l<=maxlegs) flag=1;	
	}
	else flag=0;
	
	if(flag) cout<<"yes"<<endl;
	else cout<<"no"<<endl;
}
return 0;
}

Have a look at my solution https://www.codechef.com/viewsolution/17555935
It is self explanatory .

1 Like

What’s wrong in this code? https://www.codechef.com/viewsolution/18693946
Only 30%?

What’s wrong in this code? https://www.codechef.com/viewsolution/18693946

Only 30%?

what is wrong in my code .I followed editorial

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

Please help

1 Like

You’ve calculated wrong min, learn to debug your code.
ll mnl=d4;
if(c>d
2)
mnl=(ll)((ll)(c-(ll)(d*2))*4 + mnl);

Not sure why it posted in such a weird format sorry about that

nevermind I got it

Describe what you think the following input means:

1
5 5 0

and why you should not allow this as a valid situation.

Simple python Implementation.
First check if we have query between max and min number of legs possible.
Then just check if legs are multiple of 4.

t = int(input())
while(t>0):
    cats, dogs, legs = map(int, input().split())
    max_legs = (dogs + cats) * 4

if((2 * dogs) >= cats):
    min_legs = 4 * dogs

else:
    min_legs = (cats - (2*dogs)) * 4 + dogs * 4

# print(min_legs, max_legs)

if(legs < min_legs or legs > max_legs):
    print("no")

else:
    if(legs % 4 == 0):
        print("yes")
    else:
        print("no")
t -= 1

https://www.codechef.com/viewsolution/33135232
can someone pls tell why it is giving WA

wrongly consider the input order
this caused me 1 hr :frowning_face:

#include
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;

while(t--)
{
    int c,d,l;
    cin>>c>>d>>l;
    
    if(c*4 + d*4 == l)
    {
        cout<<"yes"<<endl;
    }
    else if(((c*4)-4)  + d*4 == l )
    {
        cout<<"yes"<<endl;
    }
    else if(((c*4)-8)  + d*4 == l )
    {
        cout<<"yes"<<endl;
    }
    else {
        cout<<"no"<<endl;
    }
}
return 0;

}

This code gets me 0 marks can anyone look into it ??
I have gone for 3 cases
case1: No cats on back
case2: 1 cat on back
case3: 2 cats on back

plz help me.

#include
using namespace std;

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

while(t--)
{
int c,d,l;cin>>c>>d>>l;
int s=(c+d)*4;

if(s==l || s/2==l)
cout<<"yes"<<endl;

else
cout<<"no"<<endl;

}
}

it does not works for the input 1 1 2
think !
once try reading editorial’s logic, its easy to grasp

consider this case as well
case 4: 1 cat on back of some dogs && 2 cats on the back of some other dogs
like this there are many other case.

In this case, the logic described in editorial will output “no”
the code will work on invalid case like these as well

Can someone please help me out with my solution. What am i doing wrong?. I’m getting WA for the 3rd SubTask
https://www.codechef.com/viewsolution/34720893
Thanks

Sir, in question constrains are:- 0<=C,D,L<=10^9
still then why we will use long long int ?
I think range of int is sufficient to handle C,D,L ?

#include
using namespace std;
int main()
{
int t;
cin>>t;

while(t--)
{
	long long int c,d,l,n;
	cin>>c>>d>>l;
	n=4*d;
	if(l%4!=0||(c==0&&d==0&&l!=0))
	cout<<"no"<<endl;
	else
	{
	while(n<l)
	{			
		n=n+4;
	}
	
	
	if(n>l)
	cout<<"no"<<endl;
	else if(n==l)
	cout<<"yes"<<endl;
	}
}

}

can somebody help me to figure out why my solution is wrong although it gives the right answers of example…

Try this test case
1
13 5 20

The minimum value of the legs in such cases isn’t 4*d but rather 4(c-d). The correct output is no but your code gives yes