I tried to solve Beta Round #1 - Problem A
I tried the I/O using scanf and printf. Using "%lld". But it gave a wrong answer the first test case.
While running the same code with I/O using cin and cout. It got Accepted. I could not make out what is wrong with scanning the input using scanf and printf.
I haven't seen anything such thing occur on any other judge.
Can somebody throw a light on what actually is the problem ?
I tried the I/O using scanf and printf. Using "%lld". But it gave a wrong answer the first test case.
While running the same code with I/O using cin and cout. It got Accepted. I could not make out what is wrong with scanning the input using scanf and printf.
I haven't seen anything such thing occur on any other judge.
Can somebody throw a light on what actually is the problem ?
Maybe cin and cout are better.
But sometimes they are so sloooooow.
std::sync_with_stdio(0);
treats it.Actually, using the above trick makes
cin
faster thanscanf
, andcout
is faster thanprintf
unless you useendl
, the reason is thatendl
flushes the output buffer. Usecout << something << '\n'
instead.In theory — yes, because the
cin
/cout
operators know the target type at compile time. But in practice your mileage may vary and depends on the compiler and the standard library. A few years ago I conducted extensive testing on this matter and found that sometimes iostreams was faster and sometimes it was not. But the difference was not so great, so, in my opinion, one is safe to use iostreams (withsync_with_stdio(false)
).