Mr.Whitebird's blog

By Mr.Whitebird, history, 3 months ago, In English

The only difference between the two submissions is using a lambda function vs a global function. Lambda functions made the runtime around 7 times slower.

What do you think this is because?

AC: 255501228

TLE: 255500672

so should we always prefer global functions over lambdas then?

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

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

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

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

My theory is that its because lambda functions are created each time solve() is called: in the worst case they get created 1000 times each and maybe that's the cause of slowdown

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

    Tysm, as ZergTricky has shown, the reason was pragmas. This is good motivation to learn how they actually work!

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

Why you use endl though? '\n' doesn't flush the output when combining with cin.tie(0) so it runs faster.

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

    well I figured 1000 cases wont matter much so I usually use endl for debug purposes if the output stream wont be too crowded

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

Just removed pragmas from your code. Don't use them if you don't understand when. https://codeforces.com/contest/1862/submission/255506582

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

    woah! Thank you so much! I should really learn how pragmas work...