Блог пользователя _Untrackable_

Автор _Untrackable_, история, 13 месяцев назад, По-английски

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://mirror.codeforces.com/contest/1851/submission/215759218

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
13 месяцев назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

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){
  • »
    »
    13 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      13 месяцев назад, # ^ |
        Проголосовать: нравится +8 Проголосовать: не нравится

      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.