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

Автор lbm364dl, история, 3 года назад, По-английски

I'll leave it short. I got time limit because of big input so I started submitting some IO variations. I also decided to compare with using scanf, which should be faster, but for some reason using cin with ios_base::sync_with_stdio(false) shows about 400ms (120387767) while using scanf shows about 750ms (120392401). Am I doing something wrong? Why is scanf variant slower here?

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

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

Once i also faced this issue in a problem with tight limits.
Use this for fast I/O:(only for C++ lang)
ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

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

I don't know if this is the reason for your slowdown, but sometimes compiler variants can have issues with format string parsing.

Here's one thread right here on codeforces which shows how gcc 6.2 C++14 was slower for printf and scanf, and some details on how the author tried to do something about it : <<< BLOG ENTRY 47180 BY LGM halyavin >>>

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

Have a look at this.

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

    Ok so it seems it was a 64 bit compiler issue as submitting on C++17 shows 400ms which is expected. I still don't know why it's like that (changing to an earlier version of the compiler as suggested by oversayan's comment doesn't show a significant difference from 400) but at least I know a fix. Thanks.