Hi guys!
Solving the 1574C problem ended with TIME_LIMIT_EXCEEDED. Comparing my code with the Solution I found only 2 significant differencies: ios_base::sync_with_stdio(false); cin.tie(NULL);
Just compare 130080268 with 130164765.
Adding this lines to my code I had Accepted solution. So I am surprised that C++ I/O operations without optimizations is so computationally intensive. Is there any other tips to improve the code? May be standard C I/O should be used?
Check the execution time after replacing
with
It is well-known that the std::endl manipulator flushes the standard output stream buffer after putting the new-line character. Frequent flushing of the output stream buffer can lead to TLE Verdict in competitive programming contests, and is usually needed in interactive problems only.
I often use the
tie/sync_with_stdio
calls in a single statement as follows.In very few problems, you may even need faster data I/O in C++ program. Check the following blog and its comments for more details.
G++11/17 input/output speed?
Thank you for clarifications!
With pleasure.