Hey codeforces , I was solving C. Replacement. my first submission got Accepted with awful time 1996 ms -> My first Submission
so i was looking to reduce it once using cin.tie and it doesn't work cin.tie(0) submission another way that i tried is to use scanf instead of cin and the code didn't output even sample answers correctly. and here is the strangest thing that i re-send the accepted code it gives TLE now!! so, any coding technique to reduce the time? why is my cin.tie submission Run time error? why my identical accepted submission got TLE ? Thanks.
Never use scanf with cin.tie(0). Source
AC with cin.tie(0)
thank you for your reply instead of throwing negative votes. and for your help accepted with reduced time 1652 ms still awful :D (y)
Welcome. :)
Same code with scanf and printf(171ms).
Code
PS — I am too surprised of this huge difference!
PPS — Nope, now I am not. :-P You used endl which is slow. Code (436ms).
The problem is not the use of cin/cout, but rather the use of endl. It is not just a simple newline character. It also flushesh the whole stream which causes bad performance. Try using '\n' instead of endl in such problems where there are many lines of output