Hello everyone. I just joined Codechef about a month ago and I'm really enjoying the experience. But I guess the most frustrating situation arises with a TLE. The only fast I/O technique I've learnt is pasting the following code before my program. I code in C++: std::ios::sync_with _stdio(false); cin.tie(NULL); I've seen a significant improvement in my program execution speeds, but I've hit another roadbloack. I still get a TLE even after using the above technique. So I would like to know where I can learn a few more I/O optimization techniques, be it a book, an external link or any other source of information. Thanks in advance!! asked 14 Dec '14, 14:46 ![]()
|
See brother,
Good Luck!! :) answered 14 Dec '14, 14:54
|
Include this fast input output function at the beginning of the code .
and in place of scanf("%d",&t) ; you should use this function as Scan_f(&t) ; only. I would like to make a remark here , in 99% cases problem will not demand fast IO methods , just use scanf and printf in C++ . It is the beauty of the algorithms that make the code efficient . so try to focus on your algorithms that IO methods . answered 14 Dec '14, 15:04 ![]()
|
as aptly mentioned by @rishabhprsd7 , if your program gets TLE on any online programming site, in most cases it is due to inefficient algorithm rather than slow i/o. Also, std::ios::sync_with _stdio(false); and cin.tie(NULL); are not that slow and will get you AC in almost all cases if your algorithm is efficient. answered 14 Dec '14, 15:10 ![]()
|
well as everyone said fast I/O is not much important but I disagree to that. It is necessary for you to know that there is a marked improvement in execution time by using getchar_unlocked and you must give it a try if your code is showing TLE. I tried a problem using different I/O methods and here are the results for problem http://www.codechef.com/problems/VOTERS 1) using cin :- time= 1.30 2) using scanf :- time= 0.52 3) using cin with std::ios::sync_with _stdio(false); :- time = 0.44 4) using cin with std::ios::sync_with _stdio(false); cin.tie(NULL); :- time=0.41 5) using getchar :- time = 0.34 6) using getchar_unlocked :- time = 0.15 as you can see execution time went down from 1.30 to 0.15 which is in the case when problem does not involve large I/O. So you can yourself judge the necessity of fast I/O. answered 15 Mar '15, 02:45 ![]()
|
Yes, I too faced the same problem of TLE in my code. Then I looked for some solution which took me to the two lines added in the beginning of program , i.e std::ios::sync_with _stdio(false); cin.tie(NULL); , but this too didnt worked and I again got a TLE. I would like to know if there is any other method for FAST I/O. answered 15 Jan, 11:22 ![]()
|