Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

Автор burtmacklin, история, 4 года назад, По-английски

Hi,

I am getting TLE at test case 6. I have added documentation to improve readability.

Things I have tried:

  1. Check for infinite loops : Not possible since I am keeping track of every node visited.
  2. Check time complexity : It is O(n), which should be enough for 2 second limit.
  3. Replace cin and cout with scanf and printf : Didn't work.

Thanks

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

»
4 года назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

You are passing vectors by value, which result in creation of vector in every function calls, making runtime be O(n2). Either pass it by reference or make them global.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Thanks Just_a_programmer! It is accepted now after making them global.

    I will try to read up on these C++ details further. However, if passing by value was the concern, it should have been a memory issue (assuming that program was somehow crossing the memory limit) instead of execution time issue, right?

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      No. When you pass by value, the vectors (or arrays) are copied, and for large vectors, it'll take a lot of time and result in TLE!

    • »
      »
      »
      4 года назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      When we pass by value vector is copied, it requires time as well as memory, but in most cases the memory limit is more then enough for the purpose.