Reach the point(RETPO)[wrong answer]

#include
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{

    long long int a=0,b=0,x=0,y=0,z=0,total=0,i=0;
    long long int small(long long int p,long long int q);
    cin>>total;
    for(i=0;i<total;++i)
    {
    cin>>a;
    cin>>b;
    x=fabs(a);
    y=fabs(b);
    if(y==0)
    {
        if(x%2==0)
        {
            z=2*x;
        }
        else
            z=(2*x+1);
    }
    else if(x==0)
    {
        if(y%2==0)
        {
            z=2*y;
        }
        else
            z=(2*y-1);
    }

    else if(x==y)
    {
        z=2*x;
    }
    else if(x%2!=0 && y%2!=0)
    {
        z=(2*fabs(y-x)+2*small(x,y));
    }
    else
    {
        z=(2*fabs(y-x)-1)+2*small(x,y);
    }

    cout<<z<<endl;
    }

    return 0;
}
long long int small(long long int p,long long int q)
{
    if(p>=q)
        return q;
    else
        return p;
}

What is wrong with this code…

Your code fails for many cases, out of them these are some cases :

3 2 ans -> 5

4 8 ans -> 16

2 -8 ans-> 16

.
.
.

1 Like

For x==0 or y==0, it is ok.

But for x > 0 and y > 0, you should consider the sign and parity of (y-x), not the parity of x and y.

1 Like