_Comfortably_Numb__'s blog

By _Comfortably_Numb__, history, 9 years ago, In English

In problem 220B - Little Elephant and Array my submission 36377029 got WA. Then I comment ios_base::sync_with_stdio(0) and submit the same code 36377330 again. It got accepted. Now I wonder why my first code got WA and when we should use ios_base::sync_with_stdio(0) and when we shouldn't.

»
9 years ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

I think you only use it if you are using cin and cout. Don't mix cin/scanf/cout/printf or weird things can happen.

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

I would also add that this optimisation only makes sense if your input or output have more than a constant amount of characters (e.g. if there is a valid test in which any of these reach at least a thousand), because otherwise the time you spend on executing this function overweights the time you save from input/output.

You can also use cin.tie(0) and cout.tie(0) in addition to this, they as well speed things up a bit.