dotorya's blog

By dotorya, history, 8 years ago, In English

I wrote two different codes, which differs only on order of headers. Two codes are like these:

#include <stdio.h>
#include <algorithm>
....(blahblah)....

2.


#include <algorithm> #include <stdio.h> ....(blahblah)....

Note: At (blahblah) part, there are 9 millions scanf("%d", &t) operations. Compilation options are both GNU C++14. (GNU C++14 6.2.0, which is used on Codeforces.)

For my opinion, this two code should exactly do the same operations.

But, 1st code gives 1.6ms / 2ms AC, and 2nd code gives TLE. This issue is not about server status, it's still same during many submits.

Can someone help me about what's going on here?

Note : It's not 1.6ms / 2ms, It's 1.6s / 2s

  • Vote: I like it
  • +71
  • Vote: I do not like it

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by dotorya (previous revision, new revision, compare).

»
8 years ago, # |
  Vote: I like it +19 Vote: I do not like it

What happens if you use c++11?

»
8 years ago, # |
Rev. 3   Vote: I like it +10 Vote: I do not like it

c++14 scanf problem

It seems that using scanf in <stdio.h> is much faster than others in c++14. I think if you include algorithm first will let you use the scanf that is in the algorithm but not in the stdio.h one? (just a random guess tho)

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by dotorya (previous revision, new revision, compare).