Need help in problem (ICM2008)

Problem: ICM2008 Problem - CodeChef
My solution: kishita94251 | CodeChef User Profile for Muskan | CodeChef
Showing that my answer is not correct.

pls provide the link of your solution, not your profile

1 Like

If you need test case for which your code fails is : 20 10 3 5

Actually in this question what you need to do, is if a and b are already equal then answer is obviously yes, but if they aren’t equal but c and d are equal then answer can not be Yes, because they can’t meet.

Otherwise, let k1 number of times Mr. Pr chooses c unit to move and k2 number of times he chosses d units.
In, that case if they meet then the following condition must be true:

a + k1c + k2d = b + k2c + k1d
which simplifies to:
a - b = (k2-k1)(c-d)
Since, k2 and k1 are constant, we conclude that a-b is divisble by c-d.

Implementation is simple:

    /*author - Ashutosh Chitranshi*/
    #include<bits/stdc++.h>
    using namespace std;
    #pragma GCC push_options
    #pragma GCC optimize ("unroll-loops")
    #define watch(x) cout << (#x) << " is " << (x) << "\n"
    #define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
    #define pow2(x) ((x)*(x))
    #define max3(a,b,c) max(a,max(b,c))
    #define min3(a,b,c) min(a,min(b,c))
    #define ll long long
    #define ld long double
    #define eb emplace_back
    #define pb push_back
    #define pf push_front
    #define mod 1000000007
    #define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
    #define mp make_pair
    #define ff first
    #define ss second
    #define null NULL
    #define all(c) (c).begin(),(c).end()
    #define nl "\n"
    typedef vector<int> vi;
    typedef vector<ll> vl;
    typedef vector< vi > vvi;
    typedef vector< vl > vvl;
    typedef pair< int,int > ii;
    typedef pair< ll,ll> pll;
    typedef map< ll,ll> mll;
    typedef map< int,int> mii;
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t;
        cin >> t;
        while(t--)
        {
        	ll a,b,c,d;
        	cin >> a >> b >> c >> d;
        	if(a == b)
        		cout << "YES\n";
        	else if(c!=d)
        	{
        		if(abs(a-b)%abs(c-d)==0)
        			cout << "YES\n";
        		else
        			cout << "NO\n";
        	}
        	else
        		cout << "NO\n";
        }
        return 0;
    }