Brok3nDreams's blog

By Brok3nDreams, history, 2 months ago, In English
Motivation/Original post
Code

So according to you how much time should the above code take ? Well this is what

Custom invocation says

After some googling I figured that there is something called compiler optimization which is why c++20 is taking lesser time, haven't figured out yet what really those optimizations are but will learn in future.

Lesson learned :-

  • Use C++20 for submission.
  • cout is heavy operation, think for it when limit is tight.
  • Vote: I like it
  • +7
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it +3 Vote: I do not like it

I don'nt know the exact reason for that but that is because your code runs on the edge of time limit so i think it's because every compiler have a different time for processing constants and dealing with stl.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

10^8 solutions taking under a second or two can happen, but your code has to be optimized pretty well. The intended solution here is O(tsqrt(n)).

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

assumptions are dangerous, you should not submit a solution that you think will barely pass TL, it is a bad idea as you didn't factor in the constant factor, etc... therefore always try to write an optimized solution

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I don't understand the time complexity shown in my submission. I have my submission with pretty much similar time complexity and logic as yours and my compiler too is C++17. But still, mine passed system tests and it shows the time as 0ms. Please can someone explain this? My submission : 192307776

»
2 months ago, # |
  Vote: I like it +9 Vote: I do not like it

No, your c++17 submission is 32 bit, while c++20 is 64 bit. Submitting c++17 with 64 bit compiler is also AC 192379888

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Any possible reason why 64bit is faster ?

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it +13 Vote: I do not like it

      You use long longs in your code (when you do #define int long long). I'm not sure of the exact operations, but to my understanding 32-bit implementations do operations with long longs by first deconstructing them to 32-bit integers then combining those together, while 64-bit can do the entire operation in one go.