So, something interesting happened yesterday. I was solving 1838C - No Prime Differences, I came up with an algorithm having a time complexity of O(n*m), I realized this would work given the constraints of the problem. So, I submitted it and surprisingly. I got Time Limit Exceeded (TLE) for it. At first, I thought, I might have made a mistake where I was unexpectedly running into an infinite loop.
But after trying a bunch of things, NOTHING WORKED...I was quite frustrated.. but what could have I done. So, I cursed myself for being stupid for a few minutes and then moved on with Java (I don't like java, it's too slow at times but somehow it worked, though it took 99% of the time-limit)
Later, I was going through the standing for a previous contest and saw someone in the top of the list using the two different compilers for their solution. He had first used GNU C11 compiler and then used C++23 (GCC 14-64, msys2) and surprisingly he too was getting TLE with GNU C11 compiler.
So, I thought maybe I could try to do this, so I submitted it with C++23 (GCC 14-64, msys2) and VOILA!!, It worked. (All Hail the power of C)
Now, I'm not sure, why it worked, but my best guess is the implementation of I/O functions in the two compilers, might be the reason behind the TLE and the Accepted verdict, but I could be wrong...
So, here I am, asking for help from the good people of codeforces (I don't trust the AI, don't like it either), If anyone could help me with an explanation about this.. Is it really the I/O functions that lead to gap or am I wrong?
Here, are the two submissions for reference.
Thanks in advance.
PS: I'm trying to improve so any advice would be appreciated as well.
"I'm trying to improve so any advice would be appreciated as well" are you trying to say that advices are only meant for people who are trying to improve?
Yeah, advice does help people to improve themselves, their situation and all. So, yeah..Advice is meant for people who can improve or would like to improve.
I'm not sure what you're trying to imply here. I just wanted some advice on how can I improve in general at CP. Like if you look at my profile and see how I practice. Do you think I should improve something about the way I solve problem or submit solutions.
Any advice would be helpful.
no hes implying people trying to improve are open to advice. if you're going to be pedantic, at least get it right
I didn't know, what "pedantic" meant, but I guess I am "pedantic". I'm not sure why you're so triggered and the funny thing is that it's not even the point of the blog :) I'm trying to understand why I got a TLE for the correct solution. Last part was just for someone who could give me some constructive feedback looking at the way I code.
i was responding to the other guy
God! This is so funny man... XD XD
Auto comment: topic has been updated by L3002 (previous revision, new revision, compare).
You are correct, i made a submission that just reads the input and outputs one of the 3 cases, it basically has no actual computation. Even then, it took 1400ms.
https://codeforces.net/contest/1838/submission/291505742
At least on codeforces, C++ compilers are way more optimized than C. Even rainboy (who famously codes in C) submits on C++ when necessary. I would recommend sticking with the c++ compiler (maybe learning a bit of c++ as well ;). Since it is basically a superset of C it wont harm to use it.
defnotmee: Thanks a lot. I do plan on learning C++ at least for the cp bit. C just doesn't cut it sometimes not just with speed but it doesn't have an extensive library. Thanks again.