Hi, so I’ve done the 3rd problem in November challenge just now. I’ve written the code in Java, and it showed me TLE for 2 test cases(Execution Time was shown as 2.1 seconds for both test cases), my friend suggested me to rewrite it in c++, so when I rewrote it in C++ and submitted, all test cases got accepted and the execution time was shown as 0 seconds!!!
I’m not that good at CP, I’m still learning, can someone explain me in detail why this happened ? I’ve been doing CP only in Java, but after seeing this issue, I feel like I’ve made a mistake starting competitive programming with java (or am I wrong in this perspective? ). Should I migrate to C++ ?
Choose whatever language you are comfortable in.Just know your language,how it works,what are it’s pros and cons etc etc. CP is 80% logic and 20% implementation. If you use java,keep your fast input templates ready.And all the best. P.S - I switched from JAVA to c++ in the intial days seeing all these TLE’s because of Scanner:’) . NEVER USE SCANNER for CP xD
Mate, In competitive programming, there is large input output, so you need faster ways of reading input. I suggest you to used this fastReader way of taking input. Hope it helps getting u more ACs!!..
I was facing same problem. And the reason you’re getting TLE is because you’re using Strings and “+” for concatenation I was getting TLE solution using simple strings
When I used StringBuilder instead of normal String I got all AC
So, system.out.println is THAT slow. It took 3.67 seconds to print {10}^{6} chars this way. I see. Codes which just printed string in 1 call did in 0.17 sec, while those printing char by char took ~1.8-1.9 sec.