scanf VS std::cin

which works faster in c++?
std::ios::sync+with_stdio(false)

std::cin

or
scanf
??

1 Like

http://codeforces.com/blog/entry/5217
Give this thread a read and you will get it :slight_smile:

2 Likes

std::ios::sync+with_stdio(false)

This does not increase speed of cout… Point to be noted…

Using cout.tie(0) speeds cout a bit though.

1 Like

The difference after using fast I/O (like ios_base… , cin.tie(0), cout.tie(0), using newline char instead of endl etc.) is negligible to me. If you are still getting TLE despite having correct complexity, I think your code is “crude” and needs some hardware level optimizations. Problem setters ought not to set such strict time limits, but if they feel like testing this, or demand a refined solution instead of a “crude” one, then its good to know how to optimize your code further on such level. (I often see it on hackerrank questions - correct complexity + refined solution gets easy AC, rest get stuck on 1-2 cases)

2 Likes

thanks for the link!!
quite informative as codeforces is always…

Thank you :slight_smile:

1 Like