JacobianDet's blog

By JacobianDet, history, 5 years ago, In English

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?

Problem Link: https://www.codechef.com/problems/TREEVERS

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

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

  • Vote: I like it
  • -28
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
  Vote: I like it +121 Vote: I do not like it

HOW. MANY. TIMES. CAN. WE. REPEAT. IT?

Comparator should return false on equal elements.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

OK!! Never faced something like this before. Sorry for the inconvenience caused.