Barakat.'s blog

By Barakat., history, 17 months ago, In English

Hello Codeforces,
Just got TLE on 2116C - Гелифиш и пылающий пион using __gcd, but after switching to gcd from <numeric>, my code got AC!

TLE Submission (using __gcd): Submission #322284306
AC Submission (using std::gcd): Submission #322321593

I couldn't find a clear reason online for this difference.
If anyone knows why this happens, please share in the comments section!

  • Vote: I like it
  • +10
  • Vote: I do not like it

| Write comment?
»
17 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
17 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

There's this blog where this guy explain some things about the 2 versions of gcd, since he was having some problems with it too. Might be a good reading (it was for me at least).

»
17 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

in c++17 __gcd is faster than gcd but in c++20 and c++23 gcd is faster than __gcd

»
17 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Why people even use an internal implementation when there is literal standard one??

»
17 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

remove long long you should get ac even with __gcd() due to log factor going till 64x this causes the time limit to get exceeded

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

    I did submit the same code without long long during the contes. It still gave me TLE

    • »
      »
      »
      17 months ago, hide # ^ |
      ← Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      i saw it your approach is different i'm talking about the recursive dp may there is some bug in your code other than __gcd also try initialising your dp size to max of elements not directly 5001