ADIS1's blog

By ADIS1, history, 5 weeks ago, In English

Hello, everyone. I have a problem with solving this task.

So, the main problem is — time limit. My code just can't pass tests, because tests be like: "let's go 500 lines with 500 symbols each and you gonna run it". This is my latest try on solving this task. As you can see, I'm using Python via functions and sys to decrease memory usage and speed up code, but it's not working fine.

Don't tell me: 'Use C++, Python is very slow'. No, look at this solve. Why it's working? Maybe someone who codes on Python can help with my problem.

Thanks for any advices.

 
 
 
 
  • Vote: I like it
  • -18
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

You're using $$$O(N)$$$ methods for a list. j[0] in k is $$$O(N)$$$ because it has to iterate through all elements of the list in the worst case as well as k.index(j[0]). The accepted code doesn't use such methods.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Hi, thanks for help. I was thinking about j[0] in k, but this iterating only first element of my list j[0] in second list k. If I write another construction — I will have to do the same method, because I need to iterate all list. However, I'm not sure about k.index(j[0]). Maybe I can rework it. Any advices?