Блог пользователя _Comfortably_Numb__

Автор _Comfortably_Numb__, история, 7 лет назад, По-английски

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.

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

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.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.