I was trying to solve SAMESNAK problem on codechef and came up with this solution. I have already looked at all the other questions on the forum and my code passes all the test cases which other have pointed out.

Can someone tell me where my code fails ??

Hey you can generate some random test cases and run it on your code.And run the same test cases on someone’s AC code which is now available and check the difference between the output of your and the AC one solution.For checking difference in output you can use this.

Now now, Consider this function from your code:

``````bool isColinear(pair<int, int> a, pair<int, int> b, pair<int, int> c){
return ((c.first - a.first)*(b.second - a.second) == (c.second - b.second)*(b.first - a.first));
}
``````

say,

1. first[0] is (0,0) = a
2. first[1] = (0,1000000000) = b
3. second[0] = (1000000000,0) = c

That means LHS of that compare is (1e9 * 1e9) = 1e18, you are using integer data type to store that => overflow.

1 Like

I understand other people’s approach and solution and it passes for all the random cases I generate. Can you please point out some of the cases in which the solution fails

For the below Input:

1

3 3 3 3

3 1 7 1

The output of your solution is:

yes

Whereas, the expected output should be:

no

This is because of your isColinear function.

Just replace your isColinear function with the function as given below:

``````bool isColinear(pair< int, int> a, pair< int, int> b, pair< int, int> c){
return ((a.first == b.first) && (c.first == a.first) || (a.second == b.second) &&
(c.second == a.second));
}
``````

And it will give you AC.

//