I am just curious to know that how a solution becomes faster than others. Even if we apply the same algorithm and even use I/O optimization. I solved DELISH but never saw my rank. After some days I got to know that my solution is second best. I checked out many solution even with fast I/O, all used the same logic ,the approach was entirely same. Then why my solution ran faster. I just used ternary operators , is it the reason?? Just Curious!! here’s the link http://www.codechef.com/viewsolution/2240129
It actually depends on whether the optimizations for the gcc compiler are enabled or not in the SPOJ online judge (which apparentely, they are not).
This happens because during the compiling and linkage process there’s a good chance that the ternary operators get translated into the cmov or mov Assembly like code, while the if-else block, if the optimizations are disabled will most likely get translated to a combination of cmp and jmp.
Obviously, as having only one Assembly instruction is cheaper than having two, the code with ternary operators runs faster than the one with normal if-else blocks. However, this is just a supposition from my side and might not be completely correct…