I always using c++ style cin, cout for solving problems, and hasn't got efficiency issues before. But the following problem has so much difference, please help me why this happens.
Same code with just different input method. http://codeforces.net/contest/396/submission/10835959 => scanf 343ms http://codeforces.net/contest/396/submission/10835934 => cin + sync_with_stdio(0) 1044ms
It seems scanf is much much faster than the cin method even when cin close the sync, this never happened before. I close the sync in the pre-written code: struct _ {_() {ios_base::sync_with_stdio(0);}} _;
Delete: Do not DOWNVOTE me if you think this problem is not high quality, it's hard for me to gain rating, so contribution gain will be also exciting.
**** Add: Feel free to DOWNVOTE me, if you think my contribution is high enough. Hope my sum of rating and contribution will be stable. :D
cout flushes every time you use cin. To avoid it, use cin.tie(0);
10836194
It is slightly faster, but it is still double the time compared to the scanf method which cost just 300+ms. Anyway, thank you for telling me "cin.tie(0)".
I want to downvote just because of appearance of words "do not downvote" =) Do you really mind it? You are competing for rating/contribution? Or you just enjoy it? That's only IMHO, but I think that one can think about contribution only in case if he/she wrote really good article, but nobody have seen or understood it — and downvoted because of it. And, of course, that all depend on sense of humor in many cases.