Parvej's blog

By Parvej, history, 3 years ago, In English

Today I was solving this problem.

I made two similar submissions.

Sub1 used class ( TLE ).

Sub2 exact same code without class ( AC ).

I can't understand why making the functions and variables as class's member consuming so much time?

I have googled but didn't find anything written about it.

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

»
3 years ago, # |
  Vote: I like it +6 Vote: I do not like it

Have you tried to benchmark the programs locally against each other and figure out exactly what slows down the execution?

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

    No. Actually, I don't know how to do this.

»
3 years ago, # |
  Vote: I like it +24 Vote: I do not like it

Your mod variable changes from a constant to a variable and compilers are very good at optimizing constant modulus / division operations whereas variable ones are slow.