shiv-aay's blog

By shiv-aay, history, 2 hours ago, In English

In today's contest I got TLE in one of the problems. I was using CPP (C++17 (GCC 7-32)). As soon as I replaced method call (validSubstring) to macro definition, solution got Accepted. I went ahead and tried using the method version of my solution along with inline keyword, which supposedly brings the performance of code similar to macro definition by inlining the method. However, this also resulted in TLE.

As far as my understanding goes, the reason behind failure of method version (without inline keyword) of the submission is overhead of creating extra stack frames in thread stack, parameter-passing, type-check etc. Macro definition version probably passed as it does not do any of the above activities. But I am still not sure why the inline version is failing, is it because inline keyword is ignored by the pre processor use on CF, or the slight overhead difference between inlining and macro definition is causing this TLE.

Ref:

  • Vote: I like it
  • 0
  • Vote: I do not like it

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

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

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

In the function you are passing the string s by value meaning it get's copied for every function call. Try passing it by reference.

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

if you reference s you won't get TLE

Spoiler