Блог пользователя L3002

Автор L3002, история, 9 часов назад, По-английски

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.

290776102 290775334

Thanks in advance.

PS: I'm trying to improve so any advice would be appreciated as well.

  • Проголосовать: нравится
  • -6
  • Проголосовать: не нравится

»
9 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

"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?

  • »
    »
    8 часов назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.

  • »
    »
    8 часов назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    no hes implying people trying to improve are open to advice. if you're going to be pedantic, at least get it right

    • »
      »
      »
      8 часов назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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.

»
8 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by L3002 (previous revision, new revision, compare).

»
5 часов назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

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?

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.me/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.

  • »
    »
    46 минут назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    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.