To those programmers who use the header <bits/stdc++.h> , I strongly recommend them to stop using this header.I know its convenient to use the header as you don’t need to include any other header but it isn’t any standard header of C++ and you’ve no idea what it will do to the program.
As an example I’m providing 2 of my codes. The only difference between them is that one uses <bits/stdc++.h> (and gives Wrong Answer for one of the test cases) and another does not use <bits/stdc++.h> (and gives Correct Answer for the same test case)
The one with <bits/stdc++.h> : Solution 1
The one without <bits/stdc++.h> : Solution 2
The problem is GMEDIAN, from November Long Challenge. I’ve written an editorial on the question as well.
In case you need : Editorial
#1)Here is wrong answer solution with iostream (standard i/o library) #2)Here is accepted solution with bits/stdc++.h (just used cout instead of printf)
Now should I stop using iostream too ? XD
It’s because of printf,scanf.
Though thanks for sharing.
It does seem iostream is the culprit, cstdio seems to work. However I don’t understand why iostream exposes printf and scanf at all… the reference pages definitely do not document this.
In the two solutions I have provided, I am pre-calculating the factorials at the starting of main() function.
If I calculate the factorials by calling a function, I’m again getting correct answer.
Here, I’m pre-calculating factorials by using a function fill() : https://www.codechef.com/viewsolution/21652861
There is too much of undefined behaviour of this code, it would be nice if someone answers this question.