For DISHOWN July14 same solution in C++ 4.3.2 got TLE & got AC in C

For the problem DISHOWN in JULY14 challenge I first tried in C++ 4.3.2 and got TLE
then I uploaded the same code(of course changed cin & cout to scanf and printf) got AC in C.

Admin/Anyone please exlain the reasons for this:

C++ 4.3.2 Submission(TLE): CodeChef: Practical coding for everyone

C Submission(AC): CodeChef: Practical coding for everyone

Thank’s in Advance.

Yes ‘cin’ and ‘cout’ are slower than scanf() and printf().To make them faster you can use :

int main() {
     ios_base::sync_with_stdio(false); cin.tie(0);
    // rest of your code
    return 0;
}

Here are some of the links which may help you !

http://discuss.codechef.com/questions/23083/difference-caused-in-run-time-by-scanfprintf-when-used-in-place-of-coutcin

http://discuss.codechef.com/questions/2589/scanfprintf-vs-cincout

http://discuss.codechef.com/questions/37795/printf-and-scanf-for-pair#37805

1 Like

@achaitanyasai Does that difference(cin & cout to printf & scanf) will cause this much effect I mean TLE to AC…??

It depends, if the constraints are tight(large) then you may have chance to get TLE if you use cin/cout. But in most of the cases it doesn’t matter.

@achaitanyasai Thanks… :slight_smile: