### JacobianDet's blog

By JacobianDet, history, 2 months ago, ,

In the recently concluded Codechef September Lunchtime, I faced a strange behaviour in the Div1 3rd problem. When I wrote the comparator for sorting based on inversions in this way I got SIGSEGV verdict on almost all testcases:

 bool cmpx(int A, int B) { if((zz[A] * (sze[B] - zz[B])) < (zz[B] * (sze[A] - zz[A]))) return 0; else return 1; }

But, when I just reversed the condition for A and B in this, all testcases passed:

 bool cmpx(int A, int B) { if((zz[B] * (sze[A] - zz[A])) < (zz[A] * (sze[B] - zz[B]))) return 1; else return 0; }

Can anyone explain this strange behaviour as I'm unable to understand this?

SIGSEGV Solution: https://www.codechef.com/viewsolution/26846332

AC Solution: https://www.codechef.com/viewsolution/26847767

• -28

 » 2 months ago, # |   +121 HOW. MANY. TIMES. CAN. WE. REPEAT. IT?Comparator should return false on equal elements.
•  » » 2 months ago, # ^ |   +10 Repeating (povtorenie) is a mother (mat') of learning (uchenia).
 » 2 months ago, # |   0 OK!! Never faced something like this before. Sorry for the inconvenience caused.
 » 2 months ago, # |   +1