Hello everyone, If one does not use C-style printf/scanf in code, then I would insist on using sync_with_stdio(false), even for interactive problems.
Otherwise, it's better not to use cin/cout at all (I/O speed may become an issue). >From my knowledge and experience: 1. sync_with_stdio(false) is perfectly fine and recommended unless you use printf/scanf-based I/O in your code. 2. cin.tie(0) is fine even in interactive problems as long as you remember to flush your output before reading from (cin). By flushing the output I mean either of the following: - using (cout << endl) instead of (cout << '\n'); - using cout.flush() explicitly. And, by the way, avoid using (cout << endl) in all other cases, if I/O speed is important. Have a nice day! Michael. P.S. There is a belief that sync_with_stdio(false) can make your I/O thread-unsafe, even if your program does not use stdio.h at all. I never investigated that myself (sharing an I/O stream between threads does not sound for me like a good idea anyway). https://stackoverflow.com/a/31165481 http://www.cplusplus.com/reference/ios/ios_base/sync_with_stdio/ (Sent from a mobile device.) On Tue, Apr 16, 2019, 21:04 Xiongqi ZHANG <[email protected]> wrote: > Would you mind sharing your code? > > And I assume you know the consequence of using those fastIO tricks. > > > ios_base::sync_with_stdio(false); > > This means you can no longer mix scanf/cin or printf/cout > > > cin.tie(NULL); > > This means cout (or any other stream) will NOT be flushed before you read > any data from cin. > > > I highly discourage using any fast I/O trick in interaction problem > because the data your program is not a static file but generated using your > output. > Any fast I/O trick that put cin/cout un-synced would cause unexpected > result. > > > > Golf Gophers was an interactive problem that was asked recently in > CodeJam Round A. > > > > I used fast IO during the contest but I was getting TLE verdict because > i was using : > > > > ios_base::sync_with_stdio(false);cin.tie(NULL); > > > > After the contest, when I tried to run it without the above line of code > it passed. > > > > Now this line of code is being used by C++ programmers for ages for fast > IO but for some reason it didn't work during the contest. > > > > Can we not use fast io in interactive problems or is this a bug in > compiler? > > > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/CABUXKX6K2-aFtWy3_DvhDnySOjtw0MbC3McuL81Rw-_BRc6f8w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
