_Untrackable_'s blog

By _Untrackable_, history, 16 months ago, In English

Hi, everyone. I am getting TLE in test case 11 in Codeforces Round 888 (Div. 3) E (Nastya and Potions) . i have applied recursion to get solution for each potions. can i anyone tell me how can i fix this error??

sumbission link:- https://codeforces.net/contest/1851/submission/215759218

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

| Write comment?
»
16 months ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

When calling the recursive function, make sure to pass all vectors by reference, not just the first two:

int res2(int i,vector<vector<int>>&v,vector<int>&price,vector<bool>check,vector<int>c){
  • »
    »
    16 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    can u tell me the reason why i was getting tle??

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

      If you pass the vector without reference, it copies the vector into a new vector for the function, which increases the time complexity to O(n) at every call.

      But when you pass it with reference, the function operates on the same vector without copying.

      It's more like calling by reference vs calling by value.